PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000223. Truy vấn tổng hình hộp bốn chiều (Four-dimensional Prefix Sum)
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 bốn chiều (Four-dimensional Prefix Sum)
Four-dimensional Prefix Sum
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a static four-dimensional integer array of sizes , indexed from 1, each query gives eight integers . Sum entries whose coordinates satisfy for all four axes. All intervals are inclusive and nonempty.
Input
The first line contains . The next lines contain integers each, in increasing lexicographic order of , with increasing within a line. Then follow lines of .
Output
Print lines, one answer per query.
Subtasks
- Subtask 1 (20 points): (); ; ; ().
- Subtask 2 (30 points): (); ; ; (); ().
- Subtask 3 (50 points): (); ; ; ().
Example 1
Input
2 1 2 2 3
1 2
3 4
5 6
7 8
1 2 1 1 1 2 1 2
2 2 1 1 1 2 2 2
1 1 1 1 2 2 1 1
Output
36
14
3
Explanation
The first query includes all eight entries; the second includes 6 and 8; the third selects 3.
Example 2
Input
1 1 1 2 1
-5 2
1 1 1 1 1 1 1 2
Output
-3
Explanation
The two entries sum to −3.