PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000222. Truy vấn tổng vùng Manhattan (Rotated Coordinates)
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 vùng Manhattan (Rotated Coordinates)
Rotated Coordinates
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a static weighted matrix indexed from 1, each query asks for the sum of all cells inside the matrix satisfying , including the center. Weights may be negative.
Input
The first line contains , followed by rows of integers. Each of the next lines contains .
Output
Print lines, one answer per query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; ; .
Example 1
Input
3 3 3
1 2 3
4 5 6
7 8 9
2 2 1
1 1 1
1 1 6
Output
25
7
45
Explanation
The first query includes the center and four neighbors. The second includes three cells. The third covers the entire grid.
Example 2
Input
1 3 2
-2 3 -4
1 2 0
1 2 1
Output
3
-3
Explanation
Radius zero selects 3; radius one selects the entire row.