MRECT1 - Điểm trên cạnh hình chữ nhật - HRASTOVI

题意翻译

给你$n$个点,共$p$次询问,每次询问给定一个左下角坐标为$(x_1,y_1)$,右上角坐标为$(x_2,y_2)$的矩形,问你有多少个点__恰好落在矩形的边界上__。 ##### 输入格式: 第$1$行包含一个整数$n(1\leqslant n\leqslant 3\times 10^5)$,表示点的数量。 接下来$n$行,第$i+1$行包含两个整数$x_i,y_i(1\leqslant x_i,y_i\leqslant 10^{9})$,表示每个点的坐标。保证没有两个点坐标相同。 第$n+2$行包含一个整数$p(1\leqslant p\leqslant 10^5)$,表示询问的数量。 接下来$p$行,第$n+j+2$行包含四个整数$x_{1j},y_{1j},x_{2j},y_{2j}(1\leqslant x_{1j}<x_{2j}\leqslant 10^9,1\leqslant y_{1j}<y_{2j}\leqslant 10^9)$,表示了一个矩形,其左下角的坐标为$(x_{1j},y_{1j})$,右上角的坐标为$(x_{2j},y_{2j})$,问你有多少个点__恰好落在这个矩形的边界上__。 ##### 输出格式: 输出$p$行,每行一个整数,按照输入顺序依次表示每个询问的答案。

题目描述

The government is planing to build a walkway for tourists in the middle of an oak forest. The forest can be represented as plane with N special lattice points representing oaks. The walkway is represented as a rectangle with sides parallel to the axes. If the sides of walkway rectangle intersect any oak lattice points, such oaks need to be axed down. Oaks inside the rectangle do not represent problems and need not be cut down. Ljubo is the state secretary of Forestry and an passionate nature lover, so he ordered the secretary of Tourism to provide him with a list of P possible rectangle walkways that are attractive enough to draw in tourists. Ljubo plans to select the walkway that needs the smallest amount of oak trees to be cut down. Since we also like trees, would you be so kind and write a program that will determine the number of oaks that will be cut down for each walkway. Remember only the oaks intersecting the sides of the rectangle need to be cut.

输入输出格式

输入格式


The first line of input contains one integer N (1 ≤ N ≤ 300 000), number of oaks. The next N lines contain two integers each X i Y (1 ≤ X, Y ≤ 10^9) coordinates of oaks. There will be at most one oak on each lattice point. The next line contains one integer P (1 ≤ P ≤ 100 000), number of walkways. The next P lines contain four integers each X1, Y1, X2 , Y2 (1 ≤ X1 < X2 ≤ 10^9, 1 ≤ Y1 < Y2 ≤ 10^9) coordinates of the lower left (X1, Y1) and upper right (X2, Y2) corner of the rectangle. ![](https://luogu-ipic.oss-cn-shanghai.aliyuncs.com/20181018095524.png)

输出格式


Output P integers, one per line, the number of oaks that need to be cut down for each walkway in the order they are presented in the input.

输入输出样例

输入样例 #1


6 
1 2 
3 2 
2 3 
2 5 
4 4 
6 3 
4 
2 2 4 4 
2 2 6 5 
3 3 5 6 
5 1 6 6

输出样例 #1


3 
4 
0 
1