Meteor Shower
BOOM! POW! CRACK!
As your rocket rapidly escapes Earth, you find yourself racing through the asteroid belt — your rocket's hull pelted with flying chunks of stone. You didn't think the asteroid belt was so dense! Either way, you need to stop your ship from breaking apart!
The side of your skip is represented as an grid. A sequence of
events occur. Either:
HIT x1 y1 x2 y2
: An asteroid will strike the rectangular patch on your ship between(top-left corner) and
(bottom-right corner), dealing
damage to each cell in the patch.
SCAN x1 y1 x2 y2
: You scan the rectangular patch on your ship between(top-left corner) and
(bottom-right corner), reporting how much total damage their is to this area.
You need to stay on top of things. Handle all the events, and you might just survive!
Input
The first line consists of two integers
and
, the size of your rocket's hull.
The next line consists of a single integer
, the number of events that will occur.
The next lines describe the events in the order they occur. They are in one of the two forms described above:
HIT x1 y1 x2 y2
SCAN x1 y1 x2 y2
where and
.
Output
For each SCAN
query, output the total amount of damage to your rocket in the scanned patch.\
Fixes
- Maximal cases have been added to this question to filter out brute-force submissions.
Example
Input 1
3 3
6
SCAN 0 0 2 2
HIT 0 0 1 1
HIT 0 2 2 2
SCAN 1 1 2 2
HIT 1 1 2 2
SCAN 0 0 1 2
Output 1
0
3
8
See below for how the events are processed.
Input 2
4 4
5
HIT 0 0 3 3
SCAN 0 0 3 3
HIT 1 1 1 1
HIT 2 2 2 2
SCAN 0 0 3 3
Output 2
16
18
Comments