#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 ideas arranged in a line in his 2D brain. Each idea has a difficulty value ; larger values mean harder problems.
MloVtry plans to consult 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 -th easiest idea in the sequence (i.e., the idea with the -th smallest difficulty).
MloVtry has a “pit” in his brain. Oddly enough, this pit helps him think, but it causes the sequence to be updated. Specifically, suppose the pit is at the -th idea; then define a transformed array by
- if , then ;
- if , then .
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 , meaning the pit is at position , and he wants to ask about the -th easiest idea. Please tell MloVtry what that idea’s difficulty is, i.e., the -th smallest value in the transformed array defined by the current pit position.
To prevent “time-axis rolling,” the input for each query is obfuscated using the last answer. Let be the answer to the previous query (with initially). For each query, before using and , update them as follows: , , then compute the answer and set to this answer.
All arrays are 1-indexed.
Input Format
- The first line contains three integers , , .
- The second line contains integers .
- The next lines each contain two integers and . For each query, first transform the given and using as: , , where is the previous query’s answer (with initially).
Output Format
Output 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, .
- For 40% of the testdata, .
- There may be duplicate values. For example, for the array 1 1 1 1 1 0 the 1st smallest value is , and the 2nd through 6th smallest values are all .
Translated by ChatGPT 5
京公网安备 11011102002149号