#ABC477F. 窗口内的黑格计数 / Count Cells in a Window

窗口内的黑格计数 / Count Cells in a Window

Problem Statement

You are given a grid with NN rows and MM columns. In the ii-th row from the top, the squares from the LiL_i-th through RiR_i-th columns from the left are painted black, and the other squares are painted white.

You are given QQ queries. For each query, answer the following question.

  • You are given integers A,B,C,DA,B,C,D. Find the number of black squares contained in the rectangular region from the AA-th through BB-th rows from the top and from the CC-th through DD-th columns from the left.

Constraints

  • 1≤N,M,Q≤2×1051 \le N,M,Q \le 2\times10^5
  • 1≤Li≤Ri≤M1 \le L_i \le R_i \le M
  • For each query, 1≤A≤B≤N1 \le A \le B \le N.
  • For each query, 1≤C≤D≤M1 \le C \le D \le M.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

  • NN MM QQ
  • L1L_1 R1R_1
  • L2L_2 R2R_2
  • ⋮\vdots
  • LNL_N RNR_N
  • query1\mathrm{query}_1
  • ⋮\vdots
  • queryQ\mathrm{query}_Q

Each query queryi (1≤i≤Q)\mathrm{query}_i ~ (1 \le i \le Q) is given in the form

  • AA BB CC DD

Output

Output QQ lines. The ii-th line should contain the answer to the ii-th query.

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

Figure

The black squares are located as shown in the figure above. The 11-st query asks for the number of black squares within the blue rectangle at the upper left, the 22-nd query within the red rectangle at the lower right, and the 33-rd query within the green rectangle at the upper right.

Thus, output 4,3,04, 3, 0, respectively.

10 20 12
3 8
1 4
12 19
5 14
2 2
9 17
1 20
6 11
16 20
7 7
2 8 4 15
6 10 1 9
3 4 1 4
1 10 1 20
4 9 10 18
5 5 1 20
1 6 8 8
8 10 13 20
2 7 1 5
6 9 6 16
3 10 18 20
7 10 7 12
40
15
0
70
27
1
2
5
11
26
8
12