PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000219. Truy vấn tổng hình hộp chữ nhật (Cuboid Sum Query)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Truy vấn tổng hình hộp chữ nhật (Cuboid Sum Query)
Cuboid Sum Query
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
An array is indexed from 1 on all three axes. Each query gives . Return the sum of cells with coordinates inside the three inclusive intervals. The array is static.
Input
The first line contains . The next lines each contain integers: line of this block contains . The next line contains , followed by lines in the order .
Output
Print lines in query order, each the requested cuboid sum.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; ; .
Example 1
Input
2
1 2
3 4
5 6
7 8
2
1 2 2 2 1 1
2 2 1 2 1 2
Output
10
26
Explanation
The first query sums 3 and 7. The second takes all four cells with x=2.
Example 2
Input
3
733 857 714
956 208 257
123 719 648
840 881 245
245 112 746
306 942 694
58 870 849
13 208 789
687 906 783
8
3 3 3 3 1 1
1 3 2 3 3 3
2 2 2 3 1 1
1 3 1 1 1 1
2 3 2 3 2 3
1 2 1 1 1 2
3 3 2 2 1 3
1 2 2 3 2 3
Output
687
3917
551
1631
5180
3311
1010
4326
Explanation
The first query takes cell (3,3,1), value 687. The third sums 245 and 306. The remaining queries sum their respective cuboids.