PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000010. Truy vấn XOR trên đoạn (Range Xor Query)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Truy vấn XOR trên đoạn (Range Xor Query)

Range Xor Query

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given nonnegative integers A1,A2,…,AnA_1,A_2,\ldots,A_n, indexed from 11. The bitwise XOR operation, written ⊕\oplus, produces a 11 at a binary position exactly when one of its operands, but not both, has a 11 there. For example, 3⊕5=63\oplus5=6 because 0112⊕1012=1102011_2\oplus101_2=110_2.

Process qq operations in order. Operation 1 x y replaces AxA_x by Ax⊕yA_x\oplus y; it is neither ordinary addition nor assignment to yy.

Operation 2 x y asks for the XOR of every element from xx through yy inclusive: Ax⊕Ax+1⊕⋯⊕AyA_x\oplus A_{x+1}\oplus\cdots\oplus A_y. All queries use values reflecting preceding updates.

Input

  • Line 1: n q gives array length and operation count.
  • Line 2: A_1 A_2 ... A_n gives the initial values in index order.
  • Next qq lines: each line contains one of the following commands, in execution order:
    • 1 x y: replace AxA_x with Ax⊕yA_x\oplus y.
    • 2 x y: query XOR over inclusive interval [x,y][x,y].

Output

For each 2 x y command, print the requested integer computed from the current state on its own line, in query order. Update commands produce no output.

Subtasks

Subtask 1 (20 points):

  • 1≤n≤241\le n\le 24.
  • 1≤q≤301\le q\le 30.
  • 0≤Ai,y<2300\le A_i,y<2^{30}.
  • 1≤x≤n1\le x\le n for updates.
  • 1≤x≤y≤n1\le x\le y\le n for queries.

Subtask 2 (30 points):

  • 1≤n≤12001\le n\le 1200.
  • 1≤q≤16001\le q\le 1600.
  • 0≤Ai,y<2300\le A_i,y<2^{30}.
  • 1≤x≤n1\le x\le n for updates.
  • 1≤x≤y≤n1\le x\le y\le n for queries.

Subtask 3 (50 points):

  • 1≤n≤3000001\le n\le 300000.
  • 1≤q≤3000001\le q\le 300000.
  • 0≤Ai,y<2300\le A_i,y<2^{30}.
  • 1≤x≤n1\le x\le n for updates.
  • 1≤x≤y≤n1\le x\le y\le n for queries.

Examples

Input

3 4
1 2 3
2 1 3
2 2 3
1 2 3
2 2 3

Output

0
1
2

Explanation

There are n=3n=3 elements. The initial values are [1, 2, 3].

  1. Command 1 — 2 1 3: XOR the values [1, 2, 3]: 1⊕2⊕3=01\oplus2\oplus3=0. Print 0.

  2. Command 2 — 2 2 3: XOR the values [2, 3]: 2⊕3=12\oplus3=1. Print 1.

  3. Command 3 — 1 2 3: Position 22 becomes 2⊕3=12\oplus3=1. The new array is [1, 1, 3].

  4. Command 4 — 2 2 3: XOR the values [1, 3]: 1⊕3=21\oplus3=2. Print 2.

Collect the answers to output-producing commands in their input order, printing one answer per line.