OR and Queries
Time limit1.5sMemory limit256 MB
Process range bitwise-OR updates on an array and count how many positions in a range currently equal a fixed K.
- Level
Hard9 of 10
- Topics
- Segment tree, Bit manipulation, Implementation, Array
- Solved
- No attempts yet
Problem
You are given a sequence A1, A2, ..., AN of length N and a nonnegative integer K. Write a program that processes the following queries.
-
1 l r x: for every l ≤ i ≤ r, replace Ai with Ai ∨ x, where ∨ is the bitwise OR operation. -
2 l r: print the number of indices l ≤ i ≤ r such that Ai = K.
The sequence is indexed starting from 1.
Input
The first line gives the length of the sequence N (1 ≤ N ≤ 250,000) and K (0 ≤ K < 230).
The second line gives A1, A2, ..., AN. (0 ≤ Ai < 230)
The third line gives the number of queries M (1 ≤ M ≤ 250,000).
The next M lines each contain one query. At least one query of type 2 is given. (1 ≤ l ≤ r ≤ N, 0 ≤ x < 230)
Output
For each query of type 2, print the answer on its own line.