Under construction

Still being built. Things may change

Missing Trash

Time limit5sMemory limit1024 MB

Summary
Given an array with range assign and range AND, OR, or XOR updates, print the sum of a_i XOR i over each type 1 query range.
Level

Hard8 of 10

Topics
Segment tree, Bit manipulation
Solved
No attempts yet

Statement

After a thorough yard cleanup, the residents of Evstigraf's building bagged up the leaves and litter they had gathered and left the bags out overnight. The next morning, all the trash was gone. The only thing left is a strange device labeled 'УсТнЫй СчЁт 3000'. The thief left it as a hint, so you need to figure out the device before you can learn anything about the thief.

The device tests your mental arithmetic. It shows an array a1,…,ana_1, \ldots, a_n, then asks for operations on segments [l,r][l, r]:

  1. Compute ∑i=lr(ai⊕i)\sum_{i=l}^{r} (a_i \oplus i), where ⊕\oplus is the XOR of two numbers.
  2. Set every element of [l,r][l, r] to xx.
  3. Apply a bitwise AND, OR, or XOR with xx to every element of [l,r][l, r].

Input

The first line contains two integers nn and mm, the number of elements in the array and the number of queries (1≤n,m≤1051 \le n, m \le 10^5).

The second line contains nn integers a1,…,ana_1, \ldots, a_n (0≤ai<2150 \le a_i < 2^{15}).

Each of the next mm lines describes a query.

  • Type 1: 1 ll rr
  • Type 2: 2 ll rr xx
  • Type 3: 3 ll rr xx cc, where cc is the operation: & for AND, | for OR, or ^ for XOR.

In every query, 1≤l≤r≤n1 \le l \le r \le n and 0≤x<2150 \le x < 2^{15}.

Output

For each query of type 1, print the requested sum on its own line.

Examples1

  1. Example 1

    Input
    5 6
    3 0 11 21 17
    1 2 5
    2 1 3 9
    1 1 4
    3 3 5 23 ^
    3 2 4 19 &
    1 1 5
    
    Expected output
    47
    46
    37