luogu#P8120. 「RdOI R3.5」RMSQ

「RdOI R3.5」RMSQ

Problem Description

You are given a permutation bb of length mm and a sequence aa of length nn.

If a sequence SS can be matched, from left to right by positions, to the positions from left to right of some interval of bb, then we call SS a "beautiful sequence".

You are given qq queries. In each query, two integers ll and rr are given. You need to find, within the subarray [l,r][l,r] of aa, 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 m,n,q,Tm,n,q,T, where the meanings of n,m,qn,m,q are as described in the statement, and TT indicates whether online processing is forced.
  • The second line contains mm integers b1,b2,,bmb_1,b_2,\cdots,b_m.
  • The third line contains nn integers a1,a2,,ana_1,a_2,\cdots,a_n.
  • The next qq lines each contain two integers l,rl',r'. If T=1T=1, you need to compute the real l,rl,r by bitwise XOR of ll' and rr' with lastans\mathit{lastans}. Here, lastans\mathit{lastans} is defined as the answer to the previous query; if there was no previous query, it is 00. Otherwise, if T=0T=0, then l=l,r=rl=l',r=r'.

Output Format

  • Output a total of qq lines.
  • On the ii-th line, output one integer, the answer to the ii-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 lastans\mathit{lastans} 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 A\textbf{A}: it is guaranteed that ai,bi,l,ra_i,b_i,l,r are uniformly random within the constraints.

For 100%100\% of the testdata, 1lrn3×1051\le l\le r\le n\le 3\times 10^5, 1aim3×1051\le a_i\le m\le 3\times 10^5, 1q1×1061\le q \le 1\times 10^6, T{0,1}T \in \{0,1\}.

Translated by ChatGPT 5