Mobile coding works. A laptop is faster for long sessions.
Problem
Given a matrix and Q queries, each query is four integers (r1, c1, r2, c2). For each query, print the sum of all elements in the submatrix with top-left (r1,c1) and bottom-right (r2,c2) (0-based, inclusive).
Input format
Input
input.txt
- Three integers: N M Q (1 ≤ N, M ≤ 20, 1 ≤ Q ≤ 10) - N rows of M integers - Q lines, each with r1 c1 r2 c2 (0 ≤ r1 ≤ r2 < N, 0 ≤ c1 ≤ c2 < M)
Output format
Output
output.txt
- Q lines: sum for each query
Example
input
2 2 2 1 2 3 4 0 0 0 1 0 0 1 1
output
3 10
💬 Discussion
Loading...💬
No comments yet. Be the first to start the discussion!
💻 No output yet.
Click Run in the editor to execute your code with the custom input.
Sample cases (from the problem)
Sample Case 1
Input
2 2 2 1 2 3 4 0 0 0 1 0 0 1 1
Expected output
3 10
Solve it your way first
Community solutions unlock after you submit a passing solution. Don't peek.
Ready to solve this challenge?
Create a free account to write code, submit solutions, and track your progress.
⌨️ Keyboard Shortcuts
Code Editor
Run Code
Ctrl
Enter
Submit Code
Ctrl
Shift
Enter
Format Code
Shift
Alt
F
Toggle Comment
Ctrl
/
Undo
Ctrl
Z
Redo
Ctrl
Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc