#P11896. 「LAOI-9」此方的座位

「LAOI-9」此方的座位

Problem Description

Konata is eating in a restaurant, and he finds that the person next to him is making a lot of noise.

For the noise made at each seat kk, the noise received at position ii is max(0,jak×abs(ik))\max(0,j-a_k\times\operatorname{abs}(i-k)), where aka_k is the attenuation coefficient of the noise, and jj is the initial loudness. The detailed definition is given below.

For the noise at each position, take the maximum value among the noises arriving at this position from all seats.

However, in order to reduce noise, the staff have built noise-reduction devices at some places. If a position ii satisfies bi=1b_i=1, then this position initially has a noise-reduction device. For a noise-reduction device, after the noise reaches the first noise-reduction device it meets on the left and the first one it meets on the right, the attenuation coefficient will become 22 times the original. Formally, suppose that for the propagation from position kk to position ii, the position of the first noise-reduction device encountered is xx. Then the noise received at position ii is $\max(0,j-a_k\times\operatorname{abs}(k-x)-2a_k\times\operatorname{abs}(i-x))$.

Note: a noise-reduction device only affects noise produced after it is built.

A drawback of the noise-reduction device is that if noise is produced at the same position as the device, then the device at that position will be destroyed immediately, meaning it will not take effect for this noise or any future noises.

Therefore, at certain times, the staff will build new noise-reduction devices at some positions.

Now, within mm unit times, at each time there may be one of three events.

  • The input format is 1 i j, meaning the person at seat ii makes a sound with loudness jj.

  • The input format is 2 i, meaning query the noise received by the person at seat ii.

  • The input format is 3 i, meaning the staff build a new noise-reduction device at position ii. If this position already has a noise-reduction device, then this operation has no effect. Of course, since a noise-reduction device only affects noise produced after it is built, building a new device at a position that has produced noise before will not cause the device to be destroyed immediately.

Input Format

The first line contains the number of seats nn and the number of events mm.

The second line contains nn numbers aia_i, where aia_i is the attenuation coefficient of the noise produced by the person at seat ii.

The third line contains nn numbers bib_i. If bib_i is 11, it means there is a noise-reduction device at this position; otherwise, there is none.

The next mm lines each describe one event.

In each event, the event type is given first. Then ii (let laslas be the last output answer, initially 00) must be transformed to obtain the real input. ii should become ((i+las1)modn)+1((i+las-1)\bmod n)+1.

Output Format

For operation 22, output the answer and print a newline.

3 2
1 1 1
0 0 0
1 1 5
2 3
3
5 5
1 2 3 4 1
1 1 0 0 1
1 1 6
1 2 8
3 1
1 1 10
2 5
6
8 5
1 2 2 1 1 2 3 1
0 0 0 0 0 0 0 0
1 1 3
2 3
3 2
1 2 4
2 5
1
0

Hint

Sample Explanation

For the first 22 samples, the transformed input is the same as the original input.

For sample 11, the only contribution comes from the 55 units of noise produced at position 11. When it reaches position 33, the noise is max(0,5(31)×1)=3\max(0,5-(3-1)\times 1)=3.

This problem uses bundled testdata.

Subtask ID nn\le Special Property Score
00 2×1032\times 10^3 None 1515
11 10510^5 There are no noise-reduction devices at any time 2020
22 There is no operation 33 1010
33 All aia_i are the same 1515
44 None 4040

For 100%100\% of the data, $1\le n,m\le 10^5,1\le a_i\le 10^9,b_i\in\{0,1\},1\le i\le n,1\le j\le 10^9$.

Translated by ChatGPT 5