Differencia

아직 제출이 없습니다시간 제한14초메모리 제한256 MB

문제

Professor Zhang has two sequences a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n and b_1,b_2,,b_nb\_1, b\_2, \ldots, b\_n. He wants to perform two kinds of operations on the sequences:

  • "+ ll rr xx": set a_ia\_i to xx for all lirl \le i \le r.
  • "? ll rr": find the number of ii such that a_ib_ia\_i \ge b\_i and lirl \le i \le r.

입력

There are multiple test cases. The first line of input contains an integer TT indicating the number of test cases. For each test case:

The first line contains four integers nn, mm, AA and BB (1n1051 \le n \le 10^{5}, 1m3,000,0001 \le m \le 3\\,000\\,000, 1A,B2161 \le A, B \le 2^{16}): the length of the sequence, the number of operations and two parameters. The second line contains nn integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n (1a_i1091 \le a\_i \le 10^9). The third line contains nn integers b_1,b_2,,b_nb\_1, b\_2, \ldots, b\_n (1b_i1091 \le b\_i \le 10^9).

As the number of operations can be rather large, the mm operations are specified by parameters AA and BB 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 ii-th operation, first call rnd(last)(\mathit{last}) three times to get ll, rr and xx (that is, l=l = rnd(last)modn+1(\mathit{last}) \bmod n + 1, r=r = rnd(last)modn+1(\mathit{last}) \bmod n + 1, x=x = rnd(last)+1(\mathit{last}) + 1). Then, if l>rl > r, you should swap their values. And at last, the ii-th operation has type '?' if (l+r+x)(l + r + x) is an even number, or type '+' otherwise. 

Note: last\mathit{last} is the answer of the latest type '?' operation. Assume last=0\mathit{last} = 0 at the beginning of each test case.

There are at most 300300 test cases, and the total size of the input is at most 88 mebibytes.

출력

For each test case, output the integer S=(_i=1miz_i)mod(109+7)S = (\sum\limits\_{i = 1}^{m}{i \cdot z\_i}) \bmod (10^9 + 7), where z_iz\_i is the answer for ii-th query. If the ii-th query is of type '+', assume z_i=0z\_i = 0.