Sheets and Paintballs
Time limit2sMemory limit512 MB
Given axis-aligned rectangles and colored points, count the distinct color labels that reach each rectangle along the vertical stacking order.
- Level
Hard8 of 10
- Topics
- Sorting, Segment tree, Simulation, DFS
- Solved
- No attempts yet
Problem
One day little Donald washed all of his white sheets. After washing them he spread them out on the ground in his backyard to dry. No two sheets touch at a corner or along an edge, and no two edges cross, but a smaller sheet may lie entirely on top of a bigger one, and one sheet may cover another one completely. Once the sheets were laid out, Donald went to bed.
Donald's friend Kim heard that the sheets were drying outside and decided to play a trick. In the attic Kim found his father's paintball gun and paintballs. The balls come in several colours, and several balls may share the same colour. As soon as Donald fell asleep, Kim walked into the backyard and started shooting at the sheets. Sheets soak up paint, so when the topmost sheet is hit, its colour bleeds down to every sheet lying beneath it. Kim used up all the balls and left in a good mood.
In the morning Donald came out to collect the sheets and found a pile of colours he had never seen. Donald likes exact data and is too shocked to think, so he asks you to count how many new colours ended up on each sheet.
Model the backyard as an infinite coordinate plane, each sheet as a rectangle with sides parallel to the axes, and each shot as a point on that plane. A shot that lands on the boundary of a sheet counts as a hit on that sheet.
A shot may miss every sheet. The coordinates of the shots are pairwise different.
Input
The first line contains the number of sheets and the number of paintballs . (, )
The -th of the next lines contains the lower left corner , and the upper right corner , of the -th sheet. (, )
The -th of the following lines contains the coordinates , where Kim's -th shot landed and the colour label of that ball. (, , )
Output
Print lines. The -th line contains the number of new colours on the -th sheet.
Hint
In the pictures the number next to a point is the colour label of that shot.

The picture for the first example.

The picture for the second example.