PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000221. Tổng đường chéo Đông Bắc – Tây Nam (Diagonal Prefix NE-SW)
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 đường chéo Đông Bắc – Tây Nam (Diagonal Prefix NE-SW)
Diagonal Prefix NE-SW
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
An integer matrix has rows and columns, indexed from 1. For each query , sum exactly cells beginning at and moving one row down and one column left each step. Both endpoints are included; all queries fit within the matrix. Values 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 4 3
2 -1 3 7
4 5 -2 6
9 8 -4 1
1 3 3
1 4 3
3 2 1
Output
17
13
8
Explanation
The requested diagonals sum to 17, 13 and 8.
Example 2
Input
2 2 1
0 -5
-2 1
1 2 2
Output
-7
Explanation
The two cells contain −5 and −2.