Meat Party
Time limit3sMemory limit1024 MB
Given meat pieces as intervals with tastiness and skewer pairs, output for each person the total tastiness of pieces both skewers pierce and no earlier person removed.
- Level
Medium6 of 10
- Topics
- Segment tree, Intervals, Sorting
- Solved
- No attempts yet
Problem
Today is the day of a meat party. To suit the party, well-grilled pieces of meat are placed on a long grill.
Treat the grill as a line segment of length , with the left end at coordinate and the right end at coordinate . Each piece of meat occupies a range on the grill and has a positive integer tastiness value. The -th piece occupies the coordinates in the interval and has tastiness . Several pieces may overlap.
people attend the party. Person 1 through person step up to the grill in order and each takes the meat they will eat. The process is as follows.
- Person brings two long skewers and pushes them into the grill at coordinates and (). A skewer pushed in at coordinate pierces every piece of meat that satisfies .
- Then the person carries the skewers back to their seat. Every piece pierced by at least one skewer is carried away together and disappears from the grill.
- A piece pierced by only one of the two skewers falls to the floor while being carried. Only pieces pierced by both skewers can be taken to the seat and eaten.
As the host, you want to know which meat each person ends up eating. Find the sum of tastiness values of the meat each person takes and eats. Exclude any meat that fell to the floor from the sum.
Input
The first line contains the number of meat pieces and the number of people .
The next lines each contain three integers , , , the interval and tastiness of the -th piece.
The next lines each contain two integers , , the coordinates where person pushes the skewers.
Output
Print lines. On the -th line, print the sum of tastiness values of the meat that person takes and eats.
Constraints
- All input values are integers.
- ()
- ()
- ()