luogu#P8120. 「RdOI R3.5」RMSQ
「RdOI R3.5」RMSQ
Problem Description
You are given a permutation of length and a sequence of length .
If a sequence can be matched, from left to right by positions, to the positions from left to right of some interval of , then we call a "beautiful sequence".
You are given queries. In each query, two integers and are given. You need to find, within the subarray of , the maximum length of a subsequence that satisfies the "beautiful sequence" condition. Note that a subsequence does not need to be contiguous.
Input Format
- The first line contains four integers , where the meanings of are as described in the statement, and indicates whether online processing is forced.
- The second line contains integers .
- The third line contains integers .
- The next lines each contain two integers . If , you need to compute the real by bitwise XOR of and with . Here, is defined as the answer to the previous query; if there was no previous query, it is . Otherwise, if , then .
Output Format
- Output a total of lines.
- On the -th line, output one integer, the answer to the -th query.
4 6 6 1
1 2 3 4
1 2 3 2 3 4
1 3
2 7
1 7
0 7
0 4
2 5
3
3
2
2
3
4
Hint
Sample Explanation
The queries after decrypting with are:
1 3
1 4
2 4
2 5
2 6
1 6
Constraints
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|c|} \hline \textbf{Subtask} & \textbf{Score} & \bm{{n,m\le}} &\bm{{q\le}} & \bm{{T=}} & \textbf{Special Property} & \textbf{Subtask Dependencies}\cr\hline 1 & 10 & 100 & 10^4 & 1 & \textbf{A} & -\cr\hline 2 & 15 & 10^5 & 10^5 & 1 & \textbf{A} & 1\cr\hline 3 & 30 & 3\times 10^5 & 10^6 & 0 & - & -\cr\hline 4 & 45 & 3\times 10^5 & 10^6 & 1 & - & 2,3\cr\hline \end{array}$$- Special property : it is guaranteed that are uniformly random within the constraints.
For of the testdata, , , , .
Translated by ChatGPT 5