Range Sum Query K
Time limit6sMemory limit512 MB
Given a K-dimensional array of N^K values, answer box-sum queries over index ranges and apply point assignments.
- Level
Medium5 of 10
- Topics
- Prefix sum, Array
- Solved
- No attempts yet
Problem
Each position indexed by integers with every value in the range to holds an integer .
You process queries on . There are two types.
The first type is 1 S_1 E_1 S_2 E_2 ... S_K E_K. For every integer with , print the sum of over all tuples where holds for each .
The second type is 2 B_1 B_2 ... B_K X. Set to .
Input
The first line contains , , and , separated by spaces.
The second line contains the integers assigned to . The -th number on this line, counting from 0, is the value at the position V[i // N^(K-1) % N + 1, i // N^(K-2) % N + 1, ..., i // N^0 % N + 1]. Here // is integer division and % is the remainder operator. The operators //, %, and + have the same precedence.
Each of the next lines contains one of the two query types described above. At least one query of the first type is given.
Output
For each query of the first type, print the answer on its own line.
Constraints
- All numbers in the input are integers.