Lunch Menu
Time limit1sMemory limit512 MB
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 days.
Seungkwan likes every menu whose spiciness is at least and at most , and Youngwoo likes every menu whose sweetness is at least and at most . The four numbers , , , change from day to day with their mood.
There are lunch menus in total, and each menu has one spiciness value and one sweetness value .
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 and the number of days . (, )
Each of the next lines contains the spiciness and the sweetness of one menu. ()
The values of are pairwise distinct, and the values of are pairwise distinct. No two different menus share a spiciness value, and no two different menus share a sweetness value.
Each of the next lines contains , , , for one day. (, , , )
Output
Print lines, one answer per day. On the -th line print the number of menus that satisfy and on the -th day.