#P9361. [ICPC2022 Xi'an R] Contests
[ICPC2022 Xi'an R] Contests
题目描述
There are contestants and they take part in contests. You are given the ranklist of each contest. The ranklist of the -th contest is a sequence , indicating that the -th contestant's rank is .
SolarPea and PolarSea are two of the contestants. SolarPea wants to prove that he is stronger than PolarSea.
Define is -stronger than , if and only if there exists a sequence of length , such that , , and for all , has a smaller rank than in at least one contest.
There are queries. In the -th query, SolarPea is contestant and PolarSea is contestant . Please find the minimum positive number such that SolarPea is -stronger than PolarSea.
输入格式
The first line contains two integers () and ().
The -th of the next lines contains intergers . It is guaranteed that is a permutaion of .
The next line contains an integer ().
Each of the next lines contains two integers and (), representing a query.
输出格式
For each query, output a number representing the answer. If there is no legal , output .
题目大意
题目描述
个选手参加了 场比赛。给出每场比赛的排行榜。第 场比赛的排行榜是一个 阶排列 ,表示选手 的排名为 。
SolarPea 和 PolarSea 也是选手。SolarPea 想要证明他比 PolarSea 更强。
定义选手 「 - 强于」选手 ,当且仅当存在长度为 的序列,满足 ,,且对于所有 ,均有 在至少一场比赛中排名小于 。
给出 组询问。在第 组询问中,SolarPea 是选手 ,PolarSea 是选手 。求出最小的正整数 ,使得 「 - 强于」。
,,,,。
输入格式
第一行两个整数 。
接下来 行,每行 个整数,表示第 场比赛的排行榜。保证 是 的排列。
接下来一行一个整数 。
接下来 行,每行两个整数 表示一组询问。
输出格式
对于每组询问,输出一行一个整数表示答案。若不存在这样的 ,输出 。
6 2
1 3 2 5 4 6
2 1 4 3 6 5
4
1 4
5 3
6 1
5 2
1
2
5
3
提示
Source: The 2022 ICPC Asia Xi'an Regional Contest Problem D.
Author: csy2005.