QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#16147. Gardener's Troubles

统计

Once upon a time, in a distant land, there was a beautiful country. The king who ruled this beautiful country was a gardening enthusiast, and he planted all kinds of exotic flowers and plants in his royal garden. One day, while strolling through the garden, the king was lost in thought and asked a gardener:

"I have been pondering a problem recently. If we arrange the flower beds into six hexagons, then..."

"Then, in essence, it is a depth-first search, Your Majesty," the gardener bowed deeply to the king.

"Hmm... I heard there is a monster called a Hydra, and it is very greedy for apple trees..."

"Yes, obviously this is a classic dynamic programming problem. We discovered the mystery behind it as early as the year 4002 N, Your Majesty."

"Damn it, what exactly is your background?"

"Your Majesty, please calm down. People in our line of work are often inexplicably asked questions related to OI, so I am just taking precautions!"

The king's dignity was wounded, which was intolerable. It seemed that ordinary difficult problems could not stump this gardener, so the king decided to use a war of attrition to exhaust his strength:

"Young man, every tree in my garden can be represented by an integer coordinate. In a moment, my knights will come to ask you in turns how many trees are within a certain rectangle. If you cannot answer immediately, you should prepare to leave!" After saying this, the king walked away angrily.

Now it was the gardener's turn to be dumbfounded; he had never prepared for such a problem. Fortunately, as the president of the "National Gardener Protection Alliance"—you—can be his last straw.

Input

The first line of the file contains two integers $n$ and $m$ ($0 \le n \le 500000$, $1 \le m \le 500000$). $n$ represents the total number of trees in the royal garden, and $m$ represents the number of queries from the knights.

The next $n$ lines each contain two integers $x_i, y_i$, representing the coordinates of the $i$-th tree ($0 \le x_i, y_i \le 10000000$).

The last $m$ lines of the file each contain four integers $a_j, b_j, c_j, d_j$, representing the $j$-th query, where the rectangle in question has $(a_j, b_j)$ as the bottom-left coordinate and $(c_j, d_j)$ as the top-right coordinate.

Output

Output $m$ lines in total, each containing one integer, which is the answer to the king's query of how many trees are in the rectangle bounded by $(a_j, b_j)$ and $(c_j, d_j)$.

Examples

Input 1

3 1
0 0
0 1
1 0
0 0 1 1

Output 1

3

Input 2

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

Output 2

0
1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.