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.