PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000210. Đếm chuyến tàu nằm trọn trong đoạn (AtCoder Express 2)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm chuyến tàu nằm trọn trong đoạn (AtCoder Express 2)

AtCoder Express 2

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN cities numbered 1 through NN on a railway. Each of the MM trains serves an interval [Li,Ri][L_i,R_i], possibly with equal endpoints. For each of the QQ queries [p,q][p,q], count trains whose entire route is contained in it: p≤Li≤Ri≤qp\le L_i\le R_i\le q. Trains with identical routes count separately.

Input

The first line contains N,M,QN,M,Q. The next MM lines contain Li,RiL_i,R_i. The following QQ lines contain p,qp,q.

Output

Print QQ lines, one count per query.

Subtasks

  • Subtask 1 (20 points): 1≤N≤201\le N\le 20; 1≤M≤801\le M\le 80; 1≤Q≤401\le Q\le 40; 1≤Li≤Ri≤N1\le L_i\le R_i\le N; 1≤p≤q≤N1\le p\le q\le N.
  • Subtask 2 (30 points): 1≤N≤5001\le N\le 500; 1≤M≤2000001\le M\le 200000; 1≤Q≤1000001\le Q\le 100000; 1≤Li≤Ri≤N1\le L_i\le R_i\le N; 1≤p≤q≤N1\le p\le q\le N; Li=RiL_i=R_i.
  • Subtask 3 (50 points): 1≤N≤5001\le N\le 500; 1≤M≤2000001\le M\le 200000; 1≤Q≤1000001\le Q\le 100000; 1≤Li≤Ri≤N1\le L_i\le R_i\le N; 1≤p≤q≤N1\le p\le q\le N.

Example 1

Input

2 3 1
1 1
1 2
2 2
1 2

Output

3

Explanation

All three routes lie in [1,2].

Example 2

Input

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

Output

1
1

Explanation

The first query contains only train 1; the second contains only train 3.

Example 3

Input

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

Output

7
9
10
6
8
9
6
7
8
10

Explanation

The two [4,7] trains are counted separately. [1,10] contains all ten trains.