Under construction

Still being built. Things may change

XOR of Three Numbers and Queries

Time limit2sMemory limit1024 MB

Summary
Given an array of values below 64, answer whether some three distinct positions in a range XOR to x, and support adding x mod 64 to every element in a range.
Level

Medium7 of 10

Topics
Segment tree, Bit manipulation, Implementation
Solved
No attempts yet

Problem

A sequence of integers A1,A2,…,ANA_1, A_2, \dots, A_N of length NN is given. Write a program that processes the following two kinds of queries.

  • 1 ll rr xx: Print 1 if there is an ordered triple (i,j,k)(i,j,k) with l≤i<j<k≤rl \le i < j < k \le r such that Ai⊕Aj⊕Ak=xA_i \oplus A_j \oplus A_k = x. Otherwise, print 0. Here, ⊕\oplus is the Bitwise XOR operation.
  • 2 ll rr xx: For every ii with l≤i≤rl \le i \le r, replace AiA_i with (Ai+x) mod 64(A_i+x) \bmod 64.

Input

The first line contains NN and QQ, separated by a space.

The second line contains NN integers A1,A2,…,ANA_1, A_2, \dots, A_N, separated by spaces.

Each of the next QQ lines contains one query.

Output

For each query of type 1, print the result on its own line, in the order the queries are given.

Constraints

  • 3≤N≤300 0003 \le N \le 300\,000
  • 1≤Q≤300 0001 \le Q \le 300\,000
  • 0≤Ai<640 \le A_i < 64
  • 1≤l≤r≤N1 \le l \le r \le N
  • For type 1 queries, r−l+1≥3r-l+1 \ge 3.
  • 0≤x<640 \le x < 64
  • All numbers in the input are integers.
  • The input contains at least one query of type 1.

Hint

Let AA be a nonnegative integer and BB a positive integer. Then A mod BA \bmod B is the remainder when AA is divided by BB. This value is a nonnegative integer.

Examples1

  1. Example 1

    Input
    8 6
    1 2 4 5 0 1 1 2
    1 1 4 0
    1 6 8 1
    1 1 4 8
    2 4 5 3
    1 3 6 10
    1 3 6 12
    
    Expected output
    1
    0
    0
    1
    0