#P6587. 超超的序列 加强

超超的序列 加强

Background

Sun 1chao always likes to talk nonsense. One day, he casually said a sequence, and then wanted to modify and sum the values at some specific positions. Since Sun 1chao is very weak, he came to you for help.

Please do not copy solutions.

Problem Description

Given a sequence aa, and two types of operations:

  • 1 x y v: add vv to all aia_i where iy(mod2x)i\equiv y\pmod {2^x}.
  • 2 x y: query the sum of all aia_i where iy(mod2x)i\equiv y\pmod {2^x}.

This problem is strictly online.

Input Format

The first line contains two integers n,mn,m.

The second line contains nn integers; the ii-th one is aia_i.

Then follow several lines, each containing several integers:

When op=1op=1, the last three integers of opop' are, in order, x,y,vx,y,v for this operation;

When op=2op=2, the last two integers of opop' are, in order, x,yx,y for this operation.

It is guaranteed that there are no extra integers in the input.

For each operation, op=(lastans+op)mod2+1op=(\operatorname{lastans}+op')\bmod 2+1.

Here lastans\rm lastans denotes the answer output by the previous query; if there has been no query before, then lastans=0\rm lastans=0.

Output Format

Output the result of each query.

5 3
1 2 3 4 6
1 2 1
1 1 1 3
2 0 0
7
25

Hint

Sample Explanation

For Sample 1:

  • For the first operation, op=2op=2, the contributing indices ii are 1,51,5, so the answer is 77.
  • For the second operation, op=1op=1, the indices ii that need to add 33 are 1,3,51,3,5, so add 33 to a1,a3,a5a_1,a_3,a_5.
  • For the third operation, op=2op=2, the contributing indices ii are 1,2,3,4,51,2,3,4,5, so the answer is 2525.

Constraints

  • For 10%10\% of the testdata, 1n,m1031\le n,m \leq 10^3.
  • For 70%70\% of the testdata, there is a newline after each operation.
  • For 100%100\% of the testdata, 1n,m2×1051\le n,m \leq 2\times10^5, 0ai,y,v,op<1070 \leq a_i,y,v,op'<10^7.
  • For operations 1 and 2, 0x200\leq x \leq 20 and 0y<2x0 \le y < 2^x.

Translated by ChatGPT 5