#P6774. [NOI2020] 时代的眼泪
[NOI2020] 时代的眼泪
Description
Xiao L likes to communicate and discuss with wise people, and the wise person often gives Xiao L some thinking problems.
Today the wise person came up with another problem for Xiao L. The wise person first abstracted space-time into a two-dimensional plane, then abstracted an event as a point on this plane, and abstracted an era as a rectangle on this plane.
For convenience, let denote that two points and on the plane satisfy and .
More specifically, the wise person is given events, represented by distinct points on the plane. The wise person is also given eras, each represented by a rectangle on the plane, where is the lower-left corner and is the upper-right corner. It is guaranteed that . We say that era contains event if and only if $(r_{i,1}, c_{i,1}) \leq (x_j, y_j) \leq (r_{i,2}, c_{i,2})$.
The wise person believes that if two events satisfy , then these two events form a regret. For all events contained in an era, the regrets formed by them are called the tears of this era, and the number of regrets is called the size of the tears of this era. Now the wise person wants Xiao L to compute the size of the tears for each era.
Xiao L understands that if he cannot answer this question, he will also become tears of the times. Please help him.
Input Format
Read from standard input.
The first line contains two integers , representing the number of events and the number of eras.
The second line contains integers , where the -th number means that event has coordinates on the plane. It is guaranteed that is a permutation of to .
Then follow lines, each containing four integers , representing the rectangle corresponding to each era.
Output Format
Output to standard output.
Output lines, each containing one integer. On the -th line, output the size of the tears of the -th era.
9 9
9 8 7 6 2 4 5 3 1
4 9 3 6
2 9 1 8
3 8 2 4
3 9 2 7
2 8 1 6
1 9 1 9
1 3 5 7
2 3 3 3
6 6 6 6
1
4
2
4
4
4
0
0
0
Hint
Explanation for Sample 1
For era , the regret it contains is (that is, the regret formed by events and , same below).
For era , the regrets it contains are .
For era , the regrets it contains are .
For era , the regrets it contains are .
For era , the regrets it contains are .
For era , the regrets it contains are .
For eras , none of them contains any regret.
Sample 2
See tears/tears2.in and tears/tears2.ans in the contestant directory.
This sample satisfies Special Constraint A (see test point constraints for details).
Sample 3
See tears/tears3.in and tears/tears3.ans in the contestant directory.
This sample satisfies Special Constraint B (see test point constraints for details).
For all test points: , , .
Test Point Constraints
The specific limits for each test point are shown in the table below:
| Test Point ID | Special Constraint | ||
|---|---|---|---|
| None | |||
| None | |||
| None | |||
Special Constraint A: For all eras , we have and .
Special Constraint B: For any two different eras, the rectangles they represent are either in a containment relationship (one rectangle is inside the other; boundaries may overlap) or are disjoint (the two rectangles share no common point; boundaries are not allowed to touch).
Special Constraint C: There are at most pairs of events that do not satisfy .
Translated by ChatGPT 5
京公网安备 11011102002149号