#FT0000171. Tổng trong khối lập phương (Cube Summation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng trong khối lập phương (Cube Summation)
Cube Summation
Source: HackerRank
Version: Phước Hưng OJ Extended
Problem Statement
An cube consists of cells indexed from 1 to on each axis. All cells initially contain 0. Process operations:
UPDATE x y z w: assign to cell , replacing its previous value, even if the cell has been updated before.QUERY x1 y1 z1 x2 y2 z2: find the sum over the inclusive box satisfying , , and .
Operations take effect in the order they are given.
Input
The first line contains . The next lines contain either UPDATE x y z w or QUERY x1 y1 z1 x2 y2 z2.
Output
For each QUERY, print the box sum as a signed 64-bit integer on its own line.
Subtask
- Subtask 1 (20 points): ; ; all coordinates lie in ; ; every query box has lower bounds no greater than upper bounds along all three axes.
- Subtask 2 (30 points): ; ; all coordinates lie in ; ; every query box has lower bounds no greater than upper bounds along all three axes.
- Subtask 3 (50 points): ; ; all coordinates lie in ; ; every query box has lower bounds no greater than upper bounds along all three axes.
Examples
Example 1
Input
4 5
UPDATE 2 2 2 4
QUERY 1 1 1 3 3 3
UPDATE 1 1 1 23
QUERY 2 2 2 4 4 4
QUERY 1 1 1 3 3 3
Output
4
4
27
Explanation
Initially only has value 4, so the first box sum is 4. Assigning 23 to does not affect the second box, whose lower corner is , so its answer stays 4. The final box contains both nonzero cells and totals .
Example 2
Input
2 5
UPDATE 2 2 2 1
QUERY 1 1 1 2 2 2
UPDATE 2 2 2 8
QUERY 2 2 2 2 2 2
QUERY 1 1 1 1 1 1
Output
1
8
0
Explanation
The first assignment sets to 1. The second assignment replaces 1 by 8 rather than adding 8. Therefore, the single-cell query returns 8. Cell was never modified and remains 0.