#P2163. [SHOI2007] 园丁的烦恼

    ID: 1142 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>搜索2007各省省选树状数组离散化上海

[SHOI2007] 园丁的烦恼

Description

It seems ordinary hard problems cannot stump this gardener. The king decided to exhaust his strength with a war of attrition: "Young man, there are nn trees in my garden, and each tree can be represented by an integer coordinate. Soon, my mm knights will come in turns to ask you how many trees lie inside a certain rectangle. If you cannot answer immediately and correctly, be ready to leave!" After saying this, the king stormed off.

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

Input Format

The first line contains two integers n,mn, m, representing the number of trees and the number of queries.

The next nn lines each contain two integers x,yx, y, indicating that there is a tree at coordinate (x,y)(x, y). It is possible that two trees share the same coordinate.

The next mm lines each contain four integers a,b,c,da, b, c, d, describing a query: count how many trees are inside the rectangle with lower-left corner (a,b)(a, b) and upper-right corner (c,d)(c, d), including the boundary.

Output Format

For each query, output a single integer on its own line indicating the answer.

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

3

Hint

Constraints and Conventions

  • For 30%30\% of the testdata, it is guaranteed that n,m10n, m \leq 10.
  • For 100%100\% of the testdata, it is guaranteed that 0n5×1050 \leq n \leq 5 \times 10^5, 1m5×1051 \leq m \leq 5 \times 10^5, 0x,y,a,b,c,d1070 \leq x, y, a, b, c, d \leq 10^7, aca \leq c, bdb \leq d.

Translated by ChatGPT 5