Under construction

Still being built. Things may change

Lunch Menu

Time limit1sMemory limit512 MB

Summary
Count the menus whose spiciness falls in [u, v] and whose sweetness falls in [x, y] for each query.
Level

Medium5 of 10

Topics
Segment tree, Sorting, Binary search
Solved
No attempts yet

Problem

Seungkwan and Youngwoo will eat lunch together for the next QQ days.

Seungkwan likes every menu whose spiciness is at least uu and at most vv, and Youngwoo likes every menu whose sweetness is at least xx and at most yy. The four numbers uu, vv, xx, yy change from day to day with their mood.

There are NN lunch menus in total, and each menu has one spiciness value aa and one sweetness value bb.

Write a program that counts, for each day, how many menus both of them like.

Input

The first line contains the number of lunch menus NN and the number of days QQ. (1≤N≤100 0001 \le N \le 100\,000, 1≤Q≤5 0001 \le Q \le 5\,000)

Each of the next NN lines contains the spiciness aa and the sweetness bb of one menu. (1≤a,b≤1091 \le a, b \le 10^9)

The values of aa are pairwise distinct, and the values of bb are pairwise distinct. No two different menus share a spiciness value, and no two different menus share a sweetness value.

Each of the next QQ lines contains uu, vv, xx, yy for one day. (1≤u≤v≤1091 \le u \le v \le 10^9, v≤u+10 000v \le u + 10\,000, 1≤x≤y≤1091 \le x \le y \le 10^9, y≤x+10 000y \le x + 10\,000)

Output

Print QQ lines, one answer per day. On the ii-th line print the number of menus that satisfy u≤a≤vu \le a \le v and x≤b≤yx \le b \le y on the ii-th day.

Examples2

  1. Example 1

    Input
    6 4
    10 50
    30 30
    20 70
    60 20
    70 40
    100 10
    1 1000 10 70
    10 30 50 70
    10 100 20 20
    30 99 1 39
    
    Expected output
    6
    2
    1
    2
    
  2. Example 2

    Input
    1 1
    5 7
    1 10 1 10
    
    Expected output
    1