#P4855. MloVtry的idea

MloVtry的idea

Description

MloVtry is very imaginative and often comes up with all kinds of strange ideas. However, as a "jun ruo" (noob), MloVtry often cannot solve the problems he proposes, so his dream of preparing a full problem set has been on hold.

Fortunately, MloVtry has some very strong friends ("dalao"), so he always asks them for help whenever he can.

Now MloVtry has nn ideas arranged in a line in his 2D brain. Each idea has a difficulty value a[i]a[i]; larger values mean harder problems.

MloVtry plans to consult qq experts, but he does not want to lower his standards by asking about ideas that are too easy, nor does he want to strain his relationships by asking about ideas that are too hard. Therefore, each time he will ask about the kk-th easiest idea in the sequence (i.e., the idea with the kk-th smallest difficulty).

MloVtry has a “pit” in his brain. Oddly enough, this pit helps him think, but it causes the sequence a[i]a[i] to be updated. Specifically, suppose the pit is at the jj-th idea; then define a transformed array b[i]b[i] by

  • if iji \le j, then b[i]=a[i]zzb[i] = a[i] - zz;
  • if i>ji > j, then b[i]=i+a[i]jb[i] = i + a[i] - j.

If that were all, MloVtry would not be confused. The problem is that the pit jumps unpredictably, so he does not know which idea to ask about at any given time.

Now MloVtry gives you several queries—each is a pair (at,k)(at, k), meaning the pit is at position atat, and he wants to ask about the kk-th easiest idea. Please tell MloVtry what that idea’s difficulty is, i.e., the kk-th smallest value in the transformed array bb defined by the current pit position.

To prevent “time-axis rolling,” the input (at,k)(at, k) for each query is obfuscated using the last answer. Let lastanslastans be the answer to the previous query (with lastans=0lastans = 0 initially). For each query, before using atat and kk, update them as follows: at=((atlastans)modn)+1at = ((at \oplus |lastans|) \bmod n) + 1, k=((klastans)modn)+1k = ((k \oplus |lastans|) \bmod n) + 1, then compute the answer and set lastanslastans to this answer.

All arrays are 1-indexed.

Input Format

  • The first line contains three integers nn, qq, zzzz.
  • The second line contains nn integers a[1],a[2],,a[n]a[1], a[2], \dots, a[n].
  • The next qq lines each contain two integers atat and kk. For each query, first transform the given atat and kk using lastanslastans as: at=((atlastans)modn)+1at = ((at \oplus |lastans|) \bmod n) + 1, k=((klastans)modn)+1k = ((k \oplus |lastans|) \bmod n) + 1, where lastanslastans is the previous query’s answer (with lastans=0lastans = 0 initially).

Output Format

Output qq lines, each containing one integer: the answer to each query.

13 12 56
10100 12208 11766 11872 11336 10815 10710 11872 11536 11988 10100 10908 10815 
11 13
1 3
3 10
1 7
8 4
7 11
11 4
5 2
13 11
13 6
3 11
11 10
10044
11932
10918
11280
10044
10759
10827
11874
12152
10759
10044
10713

Hint

  • All values fit in the 32-bit signed integer range.
  • For 100% of the testdata, n,q60000n, q \le 60000.
  • For 40% of the testdata, n,q1000n, q \le 1000.
  • There may be duplicate values. For example, for the array 1 1 1 1 1 0 the 1st smallest value is 00, and the 2nd through 6th smallest values are all 11.

Translated by ChatGPT 5