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

#BS0000123. Đếm kiện cỏ trong đoạn (Counting Haybales)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm kiện cỏ trong đoạn (Counting Haybales)

Counting Haybales

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

A farmer places nn haybales at distinct integer positions p1,…,pnp_1,\ldots,p_n on a straight road. Each of qq queries gives an inclusive interval [Aj,Bj][A_j,B_j]. Count the haybales whose positions lie inside that interval, including both endpoints.

Input

The first line contains n,qn,q. The second line contains nn pairwise distinct haybale positions pip_i. Each of the following qq lines contains interval endpoints Aj,BjA_j,B_j.

Output

Print qq lines; line jj contains the haybale count in query jj.

Subtasks

  • Subtask 1 (20 points): 1≤n,q≤201\le n,q\le 20; 0≤pi≤109; 0≤Aj≤Bj≤1090\le p_i\le 10^9;\ 0\le A_j\le B_j\le 10^9; all pip_i are distinct, 1≤i≤n1\le i\le n, 1≤j≤q1\le j\le q.
  • Subtask 2 (30 points): 1≤n,q≤25001\le n,q\le 2500; 0≤pi≤109; 0≤Aj≤Bj≤1090\le p_i\le 10^9;\ 0\le A_j\le B_j\le 10^9; all pip_i are distinct, 1≤i≤n1\le i\le n, 1≤j≤q1\le j\le q.
  • Subtask 3 (50 points): 1≤n,q≤1000001\le n,q\le 100000; 0≤pi≤109; 0≤Aj≤Bj≤1090\le p_i\le 10^9;\ 0\le A_j\le B_j\le 10^9; all pip_i are distinct, 1≤i≤n1\le i\le n, 1≤j≤q1\le j\le q.

Examples

Input

4 6
3 2 7 5
2 3
2 4
2 5
2 7
4 6
8 10

Output

2
2
3
4
1
0

Explanation

Sorted haybale positions are (2,3,5,7)(2,3,5,7). The intervals [2,3][2,3], [2,4][2,4], [2,5][2,5], [2,7][2,7], [4,6][4,6], and [8,10][8,10] contain respectively 22, 22, 33, 44, 11, and 00 bales. Thus the six output lines are 2 2 3 4 1 0 in this order.