JOI Spring Training Camp 2015/16
Original Statement / Submission Site
You plan to open a store selling Matryoshka dolls, so you have ordered N Matryoshka dolls from a factory. These dolls are numbered from 1 to N. The i-th doll (1 ≤ i ≤ N) can be regarded as a hollow circular cylinder with base diameter Ri cm and height Hi cm.
Matryoshka dolls can be stored by nesting one doll inside another. Each Matryoshka doll can store exactly one other doll that is strictly smaller in both base diameter and height. A stored doll may itself store another doll inside.
One day, the factory informs you that it cannot deliver all N dolls. Instead, only those dolls whose base diameter is at least A cm and height is at most B cm will be delivered to you.
The values of A and B may change suddenly. Therefore, for each of Q pairs (Aj, Bj) (1 ≤ j ≤ Q), you want to determine in advance the minimum number of Matryoshka dolls that will not be stored inside any other doll, no matter how you nest the delivered dolls.
Given the dimensions of the N Matryoshka dolls and Q pairs (Aj, Bj), write a program that, for each pair, determines the minimum number of dolls that will not be stored inside any other doll, no matter how you nest the delivered dolls.
Print Q lines. Each line contains the minimum number of dolls that are not nested inside any other doll for the corresponding (Aj, Bj) pair.
7 3 9 5 3 7 10 6 5 10 2 6 10 10 4 1 10 5 3 5 3 9
0 1 2
10 8 14 19 9 16 11 2 7 18 20 16 9 5 10 9 20 6 4 17 13 8 7 14 9 3 9 13 4 19 12 4 19 16 18 10 7 14
3 1 3 5 0 2 1 3