#P11008. [2016杭电多校]Differencia
[2016杭电多校]Differencia
Differencia
Problem Description
Professor Zhang has two sequences and . He wants to perform two kinds of operations on the sequences:
-
- : set to for all .
- ? : find the number of such that and .
Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case: The first line contains four integers , , and $(1 \le n \le 10^5, 1 \le m \le 3000000, 1 \le A, B \le 2^{16})$ -- the length of the sequence, the number of operations and two parameters. The second line contains integers . The third line contains integers . As there are too many operations, the operations are specified by parameters and given to the following generator routine. int a = A, b = B, C = ~(1<<31), M = (1<<16)-1; int rnd(int last) { a = (36969 + (last >> 3)) * (a & M) + (a >> 16); b = (18000 + (last >> 3)) * (b & M) + (b >> 16); return (C & ((a << 16) + b)) % 1000000000; } For the -th operation, first call rnd(last) three times to get , and (i.e. l = rnd(last) % n + 1, r = rnd(last) % n + 1, x = rnd(last) + 1). Then if , you should swap their value. And at last, the -th operation is type ?, if is an even number, or type + otherwise. Note: is the answer of the latest type ? operation and assume at the beginning of each test case.
Output
For each test case, output an integer $S=(\sum\limits_{i=1}^{m}{i \cdot z_i}) \text{ mod } (10^9 + 7)$, where is the answer for -the query. If the -th query is of type +, then .
Sample Input
3
5 10 1 2
5 4 3 2 1
1 2 3 4 5
5 10 3 4
5 4 4 2 1
1 2 3 4 5
5 10 5 6
5 4 5 2 1
1 2 2 4 5
Sample Output
81
88
87
Author
zimpha
Source
2016 Multi-University Training Contest 2