#P10158. [LSOT-2] 笼中鸟

[LSOT-2] 笼中鸟

Background

"Caged bird, caged bird"

"There is a tiny bird in the cage"

"When can it escape the prison cage"

"Night at dawn"

"Even the crane and the spirit turtle slip"

"Guess who is behind you"

Problem Description

Enomoto is experimenting with a mysterious transfer device in SPHIA’s small dark room.

There are mm sequences of length nn. He wants to verify whether the transfer device can run correctly on these sequences.

The main function of this device is to swap parts of two sequences. That is, it will choose (i,j),[l,r](i,j),[l,r], and then swap the segment [l,r][l,r] of sequence ii with the segment [l,r][l,r] of sequence jj.

Of course, to verify whether the swap is successful, he will query whether the sum of some interval of a sequence matches the expected value. Also, to avoid randomness, he will add a value to some interval of a sequence.

Enomoto knows that self likes the Fibonacci sequence very much, so to better trap self, he added another function: to determine whether an interval of a sequence ff is a special sequence satisfying fij=1kfij(modp)f_i\equiv\sum_{j=1}^kf_{i-j}\pmod p.

Formal statement:

  1. Given x,l,rx,l,r, compute i=lrax,imodp\sum_{i=l}^r a_{x,i}\bmod p.

  2. Given x,l,r,fx,l,r,f, ask whether the proposition $\forall i\in[l+f,r],a_{x,i}\equiv \sum_{j=1}^f a_{x,i-j}\pmod p$ is true.

  3. Given x,l,r,kx,l,r,k, i[l,r],ax,iax,i+k\forall i\in[l,r],a_{x,i}← a_{x,i}+k.

  4. Given x,y,l,rx,y,l,r, i[l,r],swap(ax,i,ay,i)\forall i\in[l,r],\text{swap}(a_{x,i},a_{y,i}).

Input Format

The first line contains four positive integers n,m,q,pn,m,q,p, where qq is the number of operations.

The next mm lines each contain nn integers. The jj-th number in the ii-th line represents ai,ja_{i,j}.

The next qq lines each contain four or five integers.

If the input is 1 x l r, it means performing operation 11 on interval [l,r][l,r]. If the input is 2 x l r f, it means performing operation 22 on interval [l,r][l,r]. If the input is 3 x l r k, it means performing operation 33 on interval [l,r][l,r]. If the input is 4 x y l r, it means performing operation 44 on interval [l,r][l,r].

Output Format

For each operation 11, output one positive integer per line as the answer.

For each operation 22, if the proposition is true output where is self?, otherwise output infinity loop!.

5 2 6 1000000007
1 1 2 3 5
0 0 0 0 0
1 1 2 3
1 2 2 3
2 1 1 5 2
4 1 2 2 3
1 1 1 4
1 2 1 4
3
0
where is self?
4
3

Hint

"This problem uses bundled testcases."

Subtask 1(20pts):n,q100\texttt{Subtask 1(20pts):}n,q\le100.

Subtask 2(25pts):n,q105\texttt{Subtask 2(25pts):}n,q\le10^5.

Subtask 3(25pts):\texttt{Subtask 3(25pts):} there is no operation 22.

Subtask 4(30pts):\texttt{Subtask 4(30pts):} no special properties.

For all testdata, 1n,q5×1051\le n,q\le5\times10^5, 1m101\le m\le10, 0ai,j,k<p0\le a_{i,j},k< p, 1lrn1\le l\le r\le n, 1fn1\le f\le n, 1x,ym1\le x,y\le m, xyx\not=y. It is guaranteed that pp is a randomly generated prime between 10910^{9} and 2×1092\times 10^9.


After the contest on 2024/2/13, two sets of hack data (Subtask #5) were added.

Translated by ChatGPT 5