Missing Trash
Time limit5sMemory limit1024 MB
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 , then asks for operations on segments :
- Compute , where is the XOR of two numbers.
- Set every element of to .
- Apply a bitwise AND, OR, or XOR with to every element of .
Input
The first line contains two integers and , the number of elements in the array and the number of queries ().
The second line contains integers ().
Each of the next lines describes a query.
- Type 1: 1
- Type 2: 2
- Type 3: 3 , where is the operation: & for AND, | for OR, or ^ for XOR.
In every query, and .
Output
For each query of type 1, print the requested sum on its own line.