Differencia
Time limit14sMemory limit256 MB
Given sequences a and b, process m generated operations that either assign x to a range of a or count positions in a range where a_i is at least b_i.
- Level
Hard8 of 10
- Topics
- Segment tree, Binary search, Sorting, Implementation
- Solved
- No attempts yet
Problem
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 .
The number of operations can be large, so 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 : , , . If , swap them. The operation is of type "?" if is even, and of type "+" otherwise. Here is the answer of the most recent "?" operation, and at the beginning of each test case.
Input
There are multiple test cases. The first line contains an integer , the number of test cases. For each test case, the first line contains four integers , , and (, , ). The second line contains integers (). The third line contains integers ().
There are at most test cases, and the total input size is at most mebibytes.
Output
For each test case, output the integer , where is the answer to the -th query. If the -th operation is of type "+", then .