PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000229. Tổng khung viền chữ nhật (Rectangle Border 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
Tổng khung viền chữ nhật (Rectangle Border Sum)
Rectangle Border Sum
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a static integer matrix indexed from 1, sum the cells on the border of each inclusive rectangle . A cell is counted once if its row is or or its column is or , including single-row and single-column rectangles.
Input
The first line contains , followed by rows of integers. Each of the next lines contains .
Output
Print lines, one border sum per query.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; or .
- Subtask 3 (50 points): ; ; ; ; .
Example 1
Input
3 3 3
1 2 3
4 5 6
7 8 9
1 1 3 3
2 1 2 3
2 2 2 2
Output
40
15
5
Explanation
Outer border is 45−5=40. Row 2 sums to 15; the center is 5.
Example 2
Input
2 1 1
-4
2
1 1 2 1
Output
-2
Explanation
Count each cell once: −4+2=−2.