#P17880. 玉兰 / yulan
玉兰 / yulan
Problem Description
Given two sequences of positive integers of length , the inverse Cantor expansion sequence of a sequence is defined as follows:
- Let be the length of the sequence. For all , set ;
- Construct a permutation of such that for all , . It can be proved that such a exists and is unique; this permutation is the inverse Cantor expansion sequence of . Here equals if the proposition is true, and otherwise.
There are queries. Each query gives ; consider the sequence formed by copies of , copies of , , copies of in this order, and find the value of the -th element of its inverse Cantor expansion sequence.
The input of this problem is encrypted. The input gives . Let the three numbers read in a query be , and let the answer to the previous query be (if this is the first query, ). Then $l=l'\oplus (lst\times type),r=r' \oplus (lst\times type),k=k'\oplus (lst\times type)$, where denotes the bitwise XOR operation.
Input Format
The first line of the input contains two non-negative integers , the testcase number and the encryption parameter, respectively. means this testcase is a sample.
The second line contains two positive integers , the length of the sequences and the number of queries, respectively.
The third line contains positive integers .
The fourth line contains positive integers .
The -th line of the input contains three non-negative integers , the encrypted , respectively.
Output Format
For each query, output one line containing a single number, the value of the -th element of the inverse Cantor expansion sequence of the sequence formed by copies of , copies of , , copies of in this order.
0 0
4 7
2 1 3 1
2 4 2 1
1 4 2
1 4 5
1 3 2
2 3 1
2 3 4
3 3 2
4 4 1
6
4
5
1
2
3
1
0 1
4 7
2 1 3 1
2 4 2 1
1 4 2
7 2 3
5 7 6
7 6 4
3 2 5
1 1 0
7 7 2
6
4
5
1
2
3
1
0 0
6 5
1000000000 1000000000 1000000000 1000000000 1000000000 2
1 1 1 1 1 1000000000
1 5 1
1 6 5000000000
1 6 5000000002
6 6 2
2 6 2
5000000000
1
1000000000
2
4000000001
Hint
【Sample 1 Explanation】
The intervals of the first two queries are both . After expansion we get ; taking the minimum of the -th term and gives . The corresponding permutation is , whose -nd and -th terms are and , respectively.
【Sample 2 Explanation】
This sample satisfies , and the sequences and the decrypted queries are the same as in Sample 1.
【Sample 3 Explanation】
The permutation obtained by the first query is , whose first number is .
【Sample 4】
See yulan/yulan4.in and yulan/yulan4.ans in the contestant directory.
This sample satisfies the constraints of testcase .
【Sample 5】
See yulan/yulan5.in and yulan/yulan5.ans in the contestant directory.
This sample satisfies the constraints of testcase .
【Sample 6】
See yulan/yulan6.in and yulan/yulan6.ans in the contestant directory.
This sample satisfies the constraints of testcases .
【Sample 7】
See yulan/yulan7.in and yulan/yulan7.ans in the contestant directory.
This sample satisfies the constraints of testcases .
【Sample 8】
See yulan/yulan8.in and yulan/yulan8.ans in the contestant directory.
This sample satisfies the constraints of testcases .
【Sample 9】
See yulan/yulan9.in and yulan/yulan9.ans in the contestant directory.
This sample satisfies the constraints of testcase .
【Sample 10】
See yulan/yulan10.in and yulan/yulan10.ans in the contestant directory.
This sample satisfies the constraints of testcase .
【Sample 11】
See yulan/yulan11.in and yulan/yulan11.ans in the contestant directory.
This sample satisfies the constraints of testcases .
【Sample 12】
See yulan/yulan12.in and yulan/yulan12.ans in the contestant directory.
This sample satisfies the constraints of testcases .
【Sample 13】
See yulan/yulan13.in and yulan/yulan13.ans in the contestant directory.
This sample satisfies the constraints of testcase .
【Sample 14】
See yulan/yulan14.in and yulan/yulan14.ans in the contestant directory.
This sample satisfies the constraints of testcase .
【Sample 15】
See yulan/yulan15.in and yulan/yulan15.ans in the contestant directory.
This sample satisfies the constraints of testcases .
【Sample 16】
See yulan/yulan16.in and yulan/yulan16.ans in the contestant directory.
This sample satisfies the constraints of testcases .
【Sample 17】
See yulan/yulan17.in and yulan/yulan17.ans in the contestant directory.
This sample satisfies the constraints of testcases .
【Constraints】
For all testdata:
- ;
- ;
- ;
- For all , ;
- For each query, and .
::cute-table{tuack} |Testcase No. | ||Special Property| |:-------:|:--------:|:-----:|:--:| | | | |A | | | |^ |^ | | | |^ |^ | | | |^ |^ | ||^ |^ |None | | | |^ |A | | |^ |^ |B | | |^ |^ |None | | |^ | |^ | | || |A | | |^ |^ |B | | |^ |^ |None | | |^ | |A | | |^ |^ |None |
Special Property A: For all , .
Special Property B: For all , .
Translated by QwenWork