PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000233. Truy vấn tổng hai loại đường chéo (Two Diagonal Sum Queries)
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 hai loại đường chéo (Two Diagonal Sum Queries)
Two Diagonal Sum Queries
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a static integer matrix of size , indexed from 1, query asks for the sum of exactly cells including the start. For the cells are ; for they are , where . All queried cells lie inside the matrix.
Input
The first line contains , followed by rows of integers and lines of .
Output
Print one diagonal sum per query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; ; if ; if .
- Subtask 2 (30 points): ; ; ; ; ; ; if ; if ; .
- Subtask 3 (50 points): ; ; ; ; ; ; if ; if .
Example 1
Input
3 3 3
1 2 3
4 5 6
7 8 9
1 1 1 3
2 1 3 3
2 2 2 2
Output
15
15
12
Explanation
The queried diagonals are 1+5+9, 3+5+7 and 5+7.
Example 2
Input
1 1 2
-6
1 1 1 1
2 1 1 1
Output
-6
-6
Explanation
Each query contains the only cell.