Woburn Challenge 2015-16 Round 2 - Senior Division
"The Force is strong in my family…"
"My father has it."
"I have it."
"My sister has it."
"There's one other person with that power…"
With the Death Star reduced to stardust, the evil Galactic Empire has been forced to pull out all stops in their fight against the rebels. heavily-armed Imperial starships have been deployed to fly across the galaxy, destroying all rebel resistance in their paths. All hope would seem lost, but the rebels have a powerful new Jedi ally on their side… and his name is John Cena.
John Cena has devised a plan to deal massive amounts of damage to the Imperial squadron. Upon studying stolen flight plans, he's realized that all of the enemy ships will always stay within a single plane of space. Then, treating it as a 2D Cartesian plane, he's set up a "blast zone" – a rectangle with its bottom-left corner at coordinates and its top-right corner at . He has access to a device which can set off a powerful electrical charge throughout the blast zone, damaging ships within it (including ones right on its border)!
As mentioned, John Cena has access to the Imperial flight plans, which happen to be quite simple. The -th ship will initially be located at coordinates , and will then fly in a straight line at a constant velocity of horizontal units and vertical units per second . No ship is stationary – that is, . Additionally, multiple ships may occupy the same location at any point in time.
Now, John Cena's battle plan will consist of steps. The -th step can be of one of two types, given by the value of :
- : First, wait seconds after the previous step, and then set off a charge to deal damage to each ship which is currently within the blast zone (inclusively)
- : To assess success, determine the total amount of damage dealt so far to ships
John Cena's time is now, but can you help him determine the results of each of his steps of type ?
Note: In cases worth of the points, and .
Input Specification
The first line of input consists of two space-separated integers and
.
The second line consists of four space-separated integers ,
, , and .
The next lines each consist of four space-separated integers
, , , and , for .
The next lines each consist of three space-separated integers
, , and , for .
Output Specification
For each step in the input where , output a single integer on a separate line – the total amount of damage dealt so far to ships in the range specified by and . Note that each result may not fit within a 32-bit signed integer.
Sample Input
3 14
-2 -1 3 3
7 2 -2 0
-1 -6 1 2
-1 0 0 3
1 0 5
1 1 7
2 1 2
2 1 3
1 1 1
1 0 1
2 1 3
1 1 30
1 2 6
1 1 1000
2 1 1
2 2 2
2 3 3
2 2 3
Sample Output
0
12
14
32
30
12
42
Explanation
The first charge is set off immediately, and the second occurs second later - during both of these, only the rd ship is within the blast zone, so it takes damage. The next charges both occur second after that, at which point the ships are at coordinates , and , respectively – as such, only the st ship is hit, sustaining damage. The following charge deals damage to both ships and , while neither of the last charges hit any ships.
Comments