#FT0000024. Tổng theo phép toán bit (Enjoy Sum with Operations)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng theo phép toán bit (Enjoy Sum with Operations)
Enjoy Sum with Operations
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of nonnegative integers, indexed from through . A bitwise operator combines two integers into another integer.
Process commands. Command 1 x i assigns , entirely replacing its former value. Command 2 Op l r considers every pair of distinct indices satisfying , computes the bitwise operation , and sums all such results. Op is one of the uppercase keywords XOR (exclusive OR), OR, and AND.
Every unordered pair is counted exactly once; and do not count as different pairs. If , no such pair exists, and the answer must be . Queries use the values resulting from previous assignments.
Input
- Line 1:
n qgives array length and command count. - Line 2:
a_1 a_2 ... a_ngives the initial values in index order. - Next lines: each line contains one of the following commands, in execution order:
1 x i: set .2 Op l r: sumOpover all index pairs in .
Output
For each 2 Op l r command, print the sum of Op over all position pairs . If , print . Print each answer on its own line.
Subtasks
Subtask 1 (20 points):
- .
- .
- for every initial element.
- for assignment values.
- .
- .
Opis one ofXOR,OR, orAND.
Subtask 2 (30 points):
- .
- .
- for every initial element.
- for assignment values.
- .
- .
Opis one ofXOR,OR, orAND.
Subtask 3 (50 points):
- .
- .
- for every initial element.
- for assignment values.
- .
- .
Opis one ofXOR,OR, orAND.
Examples
Input
4 3
10 20 30 40
2 OR 1 3
1 0 1
2 OR 1 3
Output
90
80
Explanation
The initial array is [10, 20, 30, 40]. The two queries only consider their specified intervals.
-
2 OR 1 3: the values in are . The three pairs are , , and . Their bitwise OR values are , , and . Thus , so print90. -
1 0 1: assign to position . The array becomes[0, 20, 30, 40]. The last element is outside the queried interval. -
2 OR 1 3: the three pairwise values now are , , and . Their sum is , so print80.
Each pair is counted only once, producing outputs 90 and 80.