Woburn Challenge 2015-16 Round 2 - Senior Division
Problem VII: The Force Awakens
“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. N (1 ≤ N ≤ 400,000) 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 (X1, Y1) and its top-right corner at (X2, Y2) (−105 ≤ X1 < X2 ≤ 105, −105 ≤ Y1 < Y2 ≤ 105). 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 i-th ship will initially be located at coordinates (sxi, syi) (−105 ≤ sxi, syi ≤ 105), and will then fly in a straight line at a constant velocity of dxi horizontal units and dyi vertical units per second (−105 ≤ dxi, dyi ≤ 105). No ship is stationary – that is, |dxi| + |dyi| > 0. Additionally, multiple ships may occupy the same location at any point in time.
Now, John Cena's battle plan will consist of M (1 ≤ M ≤ 400,000) steps. The i-th step can be of one of two types, given by the value of Ai (1 ≤ Ai ≤ 2):
- Ai = 1: First, wait Bi (0 ≤ Bi ≤ 5000) seconds after the previous step, and then set off a charge to deal Ci (1 ≤ Ci ≤ 105) damage to each ship which is currently within the blast zone (inclusively)
- Ai = 2: To assess success, determine the total amount of damage dealt so far to ships Bi..Ci (1 ≤ Bi ≤ Ci ≤ N)
John Cena's time is now, but can you help him determine the results of each of his steps of type 2?
Note: In cases worth 20% of the points, N ≤ 500 and M ≤ 2000.
Input Format
The first line of input consists of two space-separated integers N and M.
The second line consists of four space-separated integers X1, Y1, X2, and Y2
The next N lines each consist of four space-separated integers sxi, syi, dxi, and dyi, for i = 1..N.
The next M lines each consist of three space-separated integers Ai, Bi, and Ci, for i = 1..M.
Output Format
For each step in the input where Ai = 2, output a single integer on a separate line – the total amount of damange dealt so far to ships in the range specified by Bi and Ci. 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 1 second later - during both of these, only the 3rd ship is within the blast zone, so it takes 12 damage. The next 2 charges both occur 1 second after that, at which point the 3 ships are at coordinates (3, 2), (1, −2) and (−1, 6), respectively – as such, only the 1st ship is hit, sustaining 2 damage. The following charge deals 30 damage to both ships 1 and 2, while neither of the last 2 charges hit any ships.
All Submissions
Best Solutions
Point Value: 30 (partial)
Time Limit: 3.00s
Memory Limit: 256M
Added: Dec 12, 2015
Author: SourSpinach
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)