PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000232. Tổng lưới 3D ngoài một hình hộp (Sum Outside a Cuboid)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng lưới 3D ngoài một hình hộp (Sum Outside a Cuboid)
Sum Outside a Cuboid
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer cube of size , each query specifies an inclusive cuboid . Return the sum of all cells outside that cuboid. Coordinates are 1-based and the cube is static.
Input
The first line contains . The next lines contain the cube: row contains . Each of the next lines contains .
Output
Print lines, one outside sum per query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; ; .
Example 1
Input
2 3
1 2
3 4
5 6
7 8
1 1 1 2 1 2
1 2 1 2 1 2
2 2 2 2 2 2
Output
26
0
28
Explanation
The cube sums to 36. Cuboid sums are 10,36,8, giving outside sums 26,0,28.
Example 2
Input
1 1
-5
1 1 1 1 1 1
Output
0
Explanation
The cuboid covers the entire cube.