#15571. [ICPC 2022 Xi'an R] Contests
[ICPC 2022 Xi'an R] Contests
[ICPC 2022 Xi'an R] Contests
题目描述
There are $n$ contestants and they take part in $m$ contests. You are given the ranklist of each contest. The ranklist of the $k$-th contest is a sequence $a_k$, indicating that the $a_{k, i}$-th contestant's rank is $i$.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 $n$ ($2\leq n\leq 10 ^ 5$) and $m$ ($1\leq m\leq 5$).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 $l$ representing the answer. If there is no legal $l$, output $-1$.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. 标签: P9361|倍增|2022|O2优化|ICPC|西安