9593: Inversion Number Parity

内存限制:32 MB 时间限制:4 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Attention: unusual memory limit for this problem 

An inversion in a sequence is a pair of elements that are out of their natural order, and the inversion number of a permutation P = [p0, p1, …, pn-1] of 0 to (n−1) is the number of pairs (pi, pj) such that i < j and pi > pj. Given a permutation P = [p0, p1, …, pn-1] and (n−1) modifications [(l1, r1, d1), (l2, r2, d2), …, (ln-1, rn-1, dn-1)], your task is to find out the parity of the inversion number of P before and after each modification. More specifically, the permutation P will have n versions, where the first version is given as above, and for i = 1, 2, …, n−1, the (i+1)-th version is based on the i-th version after shifting the interval between indices li and ri of the permutation circularly left di times (check the note for more details), and the parity of the inversion number of P is required for each version. Additionally, since the given n is a bit large, we will generate the permutation P and modifications by the following random generator from the given n, A, B and C instead. 

The random generated sequence [f0, f1, …] is defined as:

  • ∧ means bitwise-AND, ⊕ means bitwise-XOR, and ⌊x⌋ means rounding x down to the nearest integer;let U = 230 − 1, and the undermentioned fx, gx, hx are all integers between 0 and U, inclusive;
  • let f-3 = A ∧ U, f-2 = B ∧ U and f-1 = C ∧ U;
  • for i = 0, 1, …, let gi = fi-3 ⊕ ((216 fi-3) ∧ U);
  • for i = 0, 1, …, let hi = gi ⊕ ⌊gi/25⌋;
  • for i = 0, 1, …, let fi = hi ⊕ ((2 hi) ∧ U) ⊕ fi-2 ⊕ fi-1

With the above generator,

  • x mod y (y > 0) means the remainder of x divided by y;
  • the first version of permutation P is derived from [0, 1, …, n−1] after swapping pi and pi+(fi mod (n−i)) for i = 0, 1, …, n−1 sequentially;
  • for i = 1, …, n−1, let li = min(fn+3i-3 mod n, fn+3i-2 mod n), ri = max(fn+3i-3 mod n, fn+3i-2 mod n), di = (fn+3i-1 mod n) + 1.

输入格式

The first line contains an integer T (1≤T≤10⁵), indicating the number of test cases.

Then follow T test cases. For each test case:

The only line contains four integers n, A, B and C (1≤n≤10⁷, 0≤A,B,C≤10⁹).

It is guaranteed that the sum of n over T test cases does not exceed 10⁷.

输出格式

For each test case, output a string of length nnn in one line, where the iii-th character of the string is 000 if the parity of the inversion number of the iii-th version of PPP is even, or 111 otherwise (i.e. the parity is odd).

输入样例 复制

5
3 0 0 0
3 0 0 1
3 0 1 0
3 6 7 8
10 123 456 789

输出样例 复制

000
111
111
110
1111101111

数据范围与提示

The generated sequences [f0,f1,…][f_0, f_1, \ldots][f0,f1,] for the first two test cases in the example are:
· [0,0,0,0,0,0,0,0,0,…][0, 0, 0, 0, 0, 0, 0, 0, 0, \ldots][0,0,0,0,0,0,0,0,0,];
· [1,0,202754,1,202755,692070724,692070724,692070725,792595,…][1, 0, 202754, 1, 202755, 692070724, 692070724, 692070725, 792595, \ldots][1,0,202754,1,202755,692070724,692070724,692070725,792595,].
The generated permutations and modifications for all test cases in the example are:
· P=[0,1,2]P = [0, 1, 2]P=[0,1,2]modifications=[(0,0,1),(0,0,1)]\mathrm{modifications} = [(0, 0, 1), (0, 0, 1)]modifications=[(0,0,1),(0,0,1)];
· P=[1,0,2]P = [1, 0, 2]P=[1,0,2]modifications=[(0,1,2),(1,2,2)]\mathrm{modifications} = [(0, 1, 2), (1, 2, 2)]modifications=[(0,1,2),(1,2,2)];
· P=[1,0,2]P = [1, 0, 2]P=[1,0,2]modifications=[(0,2,1),(0,1,2)]\mathrm{modifications} = [(0, 2, 1), (0, 1, 2)]modifications=[(0,2,1),(0,1,2)];
· P=[2,1,0]P = [2, 1, 0]P=[2,1,0]modifications=[(1,1,3),(1,2,3)]\mathrm{modifications} = [(1, 1, 3), (1, 2, 3)]modifications=[(1,1,3),(1,2,3)];
· P=[3,1,2,8,5,0,4,7,6,9]P = [3, 1, 2, 8, 5, 0, 4, 7, 6, 9]P=[3,1,2,8,5,0,4,7,6,9]modifications=[(1,8,2),(0,6,10),(3,5,10),(2,4,2),(7,8,9),(1,2,7),\mathrm{modifications} = [(1, 8, 2), (0, 6, 10), (3, 5, 10), (2, 4, 2), (7, 8, 9), (1, 2, 7),modifications=[(1,8,2),(0,6,10),(3,5,10),(2,4,2),(7,8,9),(1,2,7), (0,9,2),(8,9,2),(5,7,5)](0, 9, 2), (8, 9, 2), (5, 7, 5)](0,9,2),(8,9,2),(5,7,5)].
For the last test case,
· the second version of PPP is [3,8,5,0,4,7,6,1,2,9][3, 8, 5, 0, 4, 7, 6, 1, 2, 9][3,8,5,0,4,7,6,1,2,9], resulting from circularly shifting the interval of indices [1,8][1, 8][1,8] left twice (i.e. […,1,2,8,5,0,4,7,6,…][\ldots, 1, 2, 8, 5, 0, 4, 7, 6, \ldots][,1,2,8,5,0,4,7,6,] →\to […,2,8,5,0,4,7,6,1,…][\ldots, 2, 8, 5, 0, 4, 7, 6, 1, \ldots][,2,8,5,0,4,7,6,1,] →\to […,8,5,0,4,7,6,1,2,…][\ldots, 8, 5, 0, 4, 7, 6, 1, 2, \ldots][,8,5,0,4,7,6,1,2,]);
· the third version of PPP is [0,4,7,6,3,8,5,1,2,9][0, 4, 7, 6, 3, 8, 5, 1, 2, 9][0,4,7,6,3,8,5,1,2,9], resulting from circularly shifting the interval of indices [0,6][0, 6][0,6] left 101010 times (i.e. [3,8,5,0,4,7,6,…][3, 8, 5, 0, 4, 7, 6, \ldots][3,8,5,0,4,7,6,] →\to [8,5,0,4,7,6,3,…][8, 5, 0, 4, 7, 6, 3, \ldots][8,5,0,4,7,6,3,] →\to ⋯\cdots →\to [0,4,7,6,3,8,5,…][0, 4, 7, 6, 3, 8, 5, \ldots][0,4,7,6,3,8,5,]);
· the inversion numbers of all versions are 131313212121191919191919212121222222232323252525252525 and 272727 respectively.