#P8878. 『STA - R1』好吃的智慧果子

『STA - R1』好吃的智慧果子

Background

In ancient times, (20771  (mod=2035))-(2077^{-1}\ \ (mod=2035)) years ago, Morlin\mathfrak{Morlin} planted a very precious $\colorbox{black}{\textcolor{red}{\textbf{Wis♂dom♂Tree♂}}}$, which was seen by char_phi\mathfrak{char\_phi}.

After 114810114810 years, the tree bore $\colorbox{black}{\textcolor{blue}{\textbf{Wis♂dom♂Fruit♂}}}$.
After another 19195141919514 years, the fruit ripened, and char_phi\mathfrak{char\_phi} really wanted to eat it.

char_phi\mathfrak{char\_phi} wanted to eat the fruit very much, but all-knowing Morlin\mathfrak{Morlin} had already known that char_phi\mathfrak{char\_phi} wanted his fruit, so he put each fruit into a password box.

Now, char_phi\mathfrak{char\_phi} has entrusted you with the important task of stealing the fruit.

Problem Description

Formal statement

Maintain a sequence {an}\{a_n\}. In each operation, you are given five non-negative integers l,r,k,p,cl, r, k, p, c. For all i[l,r]i\in[l,r], update ai(faik+c)modpa_i\gets (f_{a_i}^k+c)\bmod p.

Here ff is the Fibonacci sequence, defined as:

$$f_n=\begin{cases}n&n\leqslant 1\\f_{n-1}+f_{n-2}&n>1\end{cases}$$

Original statement

All-knowing Morlin\mathfrak{Morlin} had long known that char_phi\mathfrak{char\_phi} was very smart, so he would change the password from time to time.

Each password box has a number on it, forming the sequence {an}\{a_n\}.

There are mm operations on the password. In each operation, five integers l,r,k,p,cl, r, k, p, c are given, meaning that for all ii satisfying lirl \leqslant i \leqslant r, change aia_i into (faik+c)modp(f_{a_i}^k+c) \bmod p (fif_i denotes the ii-th term of the Fibonacci sequence; it is guaranteed that lrl \leqslant r).

char_phi\mathfrak{char\_phi} made a recorder to record Morlin\mathfrak{Morlin}'s operations. Now, he gives you the recorder, hoping that after Morlin\mathfrak{Morlin} finishes all operations, you can figure out the passwords of all the boxes.

Input Format

The first line contains two integers n,mn, m, representing the number of fruits and the number of operations.

The second line contains nn integers as the sequence aa, representing the number on each password box.

The next mm lines describe Morlin\mathfrak{Morlin}'s operations l,r,k,p,cl, r, k, p, c.

Output Format

Output one line containing the passwords of all boxes, separated by spaces.

6 2
1 1 4 5 1 4
2 4 2 100 3
3 5 1 97 5
1 4 52 44 6 4

Hint

Constraints

This problem uses bundled testdata.

Subtask n,m\bm{n,m\leqslant} Score Special property
11 10310^3 1010 None
22 10510^5 p2p \leqslant 2
33 2020 p3p \leqslant 3
44 6060 None

For 100%100\% of the testdata, 1n,m1051 \leqslant n, m \leqslant 10^5, 1ai,p,k1001 \leqslant a_i, p, k \leqslant 100, 0c1090 \leqslant c \leqslant 10^9.

Translated by ChatGPT 5