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

#FT0000146. Nỗi khó khăn của người làm vườn (The Gardener’s Trouble)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Nỗi khó khăn của người làm vườn (The Gardener’s Trouble)

The Gardener’s Trouble

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

A royal garden contains nn trees. Tree ii has integer position (xi,yi)(x_i,y_i). Several distinct trees may share one coordinate and each must be counted separately.

There are mm independent rectangle queries. Query jj gives bottom-left corner (aj,bj)(a_j,b_j) and top-right corner (cj,dj)(c_j,d_j), with aj≤cja_j\le c_j and bj≤djb_j\le d_j. Count all trees satisfying aj≤xi≤cja_j\le x_i\le c_j and bj≤yi≤djb_j\le y_i\le d_j simultaneously. All rectangle boundaries are included. Queries do not alter the garden.

Input

The first line contains n,mn,m. The next nn lines contain the coordinates xi,yix_i,y_i of the trees. The final mm lines contain aj,bj,cj,dja_j,b_j,c_j,d_j for each rectangle.

Output

Print mm lines; line jj is the number of trees in rectangle jj.

Subtasks

  • Subtask 1 (30 points): 0≤n≤100\le n\le 10; 1≤m≤101\le m\le 10; 0≤xi,yi,aj,bj,cj,dj≤1070\le x_i,y_i,a_j,b_j,c_j,d_j\le10^7; aj≤cja_j\le c_j, bj≤djb_j\le d_j; multiple trees may have identical coordinates.
  • Subtask 2 (30 points): 0≤n≤20000\le n\le 2000; 1≤m≤20001\le m\le 2000; 0≤xi,yi,aj,bj,cj,dj≤1070\le x_i,y_i,a_j,b_j,c_j,d_j\le10^7; aj≤cja_j\le c_j, bj≤djb_j\le d_j; multiple trees may have identical coordinates.
  • Subtask 3 (40 points): 0≤n≤5000000\le n\le 500000; 1≤m≤5000001\le m\le 500000; 0≤xi,yi,aj,bj,cj,dj≤1070\le x_i,y_i,a_j,b_j,c_j,d_j\le10^7; aj≤cja_j\le c_j, bj≤djb_j\le d_j; multiple trees may have identical coordinates.

Examples

Example 1

Input

3 2
0 0
0 0
2 3
0 0 0 0
0 0 2 3

Output

2
3

Explanation

The first rectangle covers only (0,0)(0,0), where two trees stand. The second rectangle includes both (0,0)(0,0) and (2,3)(2,3) (boundaries included), thus contains all three trees.

Example 2

Input

4 3
0 2
1 1
3 3
1 1
1 1 1 1
0 0 3 3
2 0 3 2

Output

2
4
0

Explanation

Two trees share position (1,1)(1,1), giving 2 for the first query. All four trees lie in the second rectangle. The third rectangle requires 2≤x≤32\le x\le3 and 0≤y≤20\le y\le2; no tree satisfies both, since (3,3)(3,3) is too high.