A Fenwick Tree Question

View as PDF

Submit solution

Points: 15
Time limit: 0.6s
Memory limit: 64M

Author:
Problem type

Simple statement. You have a 1-indexed array with N integers, and you want to perform some Q queries on it.

  1. 1 p x: change index p to x, where 1x108
  2. 2 l r: perform the OR bitwise operation on all pairs from l to r, inclusive, then sum them
  3. 3 l r: perform the AND bitwise operation on all pairs from l to r, inclusive, then sum them
  4. 4 l r: perform the XOR bitwise operation on all pairs from l to r, inclusive, then sum them

Input Specification

The first line will contain N and Q, 1N105, 1Q104.

The second line will contain N integers.

The next Q lines will contain valid queries.

For 30% of the points, {N,x}10, Q50.

Output Specification

For each query from 2 to 4, output the sum.

Sample Input 1

Copy
6 1
4 4 8 10 4 6
2 3 6

Sample Output 1

Copy
70

Explanatioin

For the query from L=3 to R=6, there are 6 pairs:

8|10=10, 8|4=12, 8|6=14, 10|4=14, 10|6=14, 4|6=6.

So the total sum is 10+12+14+14+14+6=70.


Comments

There are no comments at the moment.