D - AtCoder Express 2 Editorial /

Time Limit: 3 sec / Memory Limit: 976 MB

配点: 400400

問題文

高橋王国には, 東西にのびる 11 本の線路がある. これに沿って NN 個の都市があり, 西から順に都市 1,2,3,,N1, 2, 3, \cdots, N と番号づけられている.
AtCoder Express という会社は MM 本の列車を保有しており, 列車 ii は都市 LiL_i から都市 RiR_i の区間 (Li=RiL_i = R_i の場合もある) を走っている.

この王国の国王である高橋君は, QQ 個のことに興味を持った. 具体的には, i=1,2,3,,Qi=1, 2, 3, \dots, Q のときの以下の質問の答えを求めたくなった.

  • 都市 pip_i から都市 qiq_i までの区間に, 走る区間が 完全に含まれる 列車の本数. 言い換えれば, piLjp_i \leq L_jRjqiR_j \leq q_i が両方成り立つような列車 jj の本数.

高橋君は天才である. しかし流石の彼でも, 膨大なデータを処理することはできない. 高橋君のために, QQ 個の質問それぞれに対して答えを求めよ.

制約

  • NN11 以上 500500 以下の整数
  • MM11 以上 200 000200 \ 000 以下の整数
  • QQ11 以上 100 000100 \ 000 以下の整数
  • 1LiRiN1 \leq L_i \leq R_i \leq N (1iM)(1 \leq i \leq M)
  • 1piqiN1 \leq p_i \leq q_i \leq N (1iQ)(1 \leq i \leq Q)

入力

入力は以下の形式で標準入力から与えられる.

NN MM QQ
L1L_1 R1R_1
L2L_2 R2R_2
::
LML_M RMR_M
p1p_1 q1q_1
p2p_2 q2q_2
::
pQp_Q qQq_Q

出力

QQ 行出力せよ. ii 行目には, 都市 pip_i から都市 qiq_i までの区間に, それぞれの走る区間が完全に含まれる列車の本数を出力せよ.


入力例 1Copy

Copy
2 3 1
1 1
1 2
2 2
1 2

出力例 1Copy

Copy
3

全ての列車の走る区間が, 都市 11 から都市 22 までの区間に含まれているので, この質問の答えは 33 となる.


入力例 2Copy

Copy
10 3 2
1 5
2 8
7 10
1 7
3 10

出力例 2Copy

Copy
1
1

11 個目の質問は, 都市 11 から 77 までの区間についてである. その区間に走る区間が完全に含まれている列車は, 列車 11 のみである. 22 個目の質問は, 都市 33 から 1010 までの区間についてである. その区間に走る区間が完全に含まれている列車は, 列車 33 のみである.


入力例 3Copy

Copy
10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10

出力例 3Copy

Copy
7
9
10
6
8
9
6
7
8
10

Score: 400400 points

Problem Statement

In Takahashi Kingdom, there is a east-west railroad and NN cities along it, numbered 11, 22, 33, ..., NN from west to east. A company called AtCoder Express possesses MM trains, and the train ii runs from City LiL_i to City RiR_i (it is possible that Li=RiL_i = R_i). Takahashi the king is interested in the following QQ matters:

  • The number of the trains that runs strictly within the section from City pip_i to City qiq_i, that is, the number of trains jj such that piLjp_i \leq L_j and RjqiR_j \leq q_i.

Although he is genius, this is too much data to process by himself. Find the answer for each of these QQ queries to help him.

Constraints

  • NN is an integer between 11 and 500500 (inclusive).
  • MM is an integer between 11 and 200 000200 \ 000 (inclusive).
  • QQ is an integer between 11 and 100 000100 \ 000 (inclusive).
  • 1LiRiN1 \leq L_i \leq R_i \leq N (1iM)(1 \leq i \leq M)
  • 1piqiN1 \leq p_i \leq q_i \leq N (1iQ)(1 \leq i \leq Q)

Input

Input is given from Standard Input in the following format:

NN MM QQ
L1L_1 R1R_1
L2L_2 R2R_2
::
LML_M RMR_M
p1p_1 q1q_1
p2p_2 q2q_2
::
pQp_Q qQq_Q

Output

Print QQ lines. The ii-th line should contain the number of the trains that runs strictly within the section from City pip_i to City qiq_i.


Sample Input 1Copy

Copy
2 3 1
1 1
1 2
2 2
1 2

Sample Output 1Copy

Copy
3

As all the trains runs within the section from City 11 to City 22, the answer to the only query is 33.


Sample Input 2Copy

Copy
10 3 2
1 5
2 8
7 10
1 7
3 10

Sample Output 2Copy

Copy
1
1

The first query is on the section from City 11 to 77. There is only one train that runs strictly within that section: Train 11. The second query is on the section from City 33 to 1010. There is only one train that runs strictly within that section: Train 33.


Sample Input 3Copy

Copy
10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10

Sample Output 3Copy

Copy
7
9
10
6
8
9
6
7
8
10


2025-04-24 (Thu)
17:17:52 +00:00