Seroogas Perboogas

View as PDF

Submit solution

Points: 6.9
Time limit: 3.9s
Memory limit: 69M

Author:
Problem type

Serog1sPerog1s was swimming around in his lake of money when he suddenly remembered that he forgot to water the Ooga crops at his Farm. He raced over to the crops as quickly as his muscular judo legs could take him and was shocked to find that his crops were sick and dying! They've been infected with the infamous Boronabirus and have turned a sickly gray colour.

After crying about it on Discord for another week, Serog1sPerog1s decides enough is enough. He contacts Professor Dave, the only man powerful enough to solve this troubling predicament. Dr. Dave proposes that this is a job for the Oogabooganator 3000 GTX 1080 Pro Galaxy Plus Cherry MX Rainbow Alpha Beta Gamma Test Release, now with 50% reduced trans fat. Dave Phd. explains that the machine can supply Booga Juice to cure any rectangular section of the crops, provided you tell it how many Oogas are in that section.

As usual, Serog1sPerog1s needs your help to do this. As we all know, math isn't really his strong suit (and don't even get me started on his atrocious chess playing), so you have to help him count the Oogas in his crops so that they won't succumb to the dreaded BOVID-20!

Input Specification

The first line of the input will contain 2 integers w and l, denoting the width and length of the entire crop farm.

The next l lines will contain w integers denoting the number of Oogas found in each crop.

The next line of input is an integer q, denoting the number of queries from the Oogabooganator.

The next q lines will contain 4 integers denoting the x, y, (of the top-left corner), width, and length of each section in the query.

For clarification, width refers to horizontal measure(x) and length refers to vertical(y).

Constraints

1 \le x, y, w, l\le 10^3

1 \le q\le 10^5

Output Specification

q lines, denoting the number of Oogas in the section for each query.

Sample Input

4 5
7 6 2 7 
5 10 6 9 
9 10 7 2 
9 3 4 4 
7 4 9 2 
6
2 1 3 2
3 3 1 3
2 4 3 1
3 3 1 3
4 2 1 3
2 1 2 4

Sample Output

40
20
11
20
15
48

Comments

There are no comments at the moment.