Блог пользователя DanceTheTragonDrainer

Автор DanceTheTragonDrainer, история, 7 лет назад, По-английски

Given N points in 2-D plane and Q queries. In each query you are given a rectangle (aligned with x,y axes) defined by the points x1, y1, x2, y2 where (x1, y1) is the lower left corner and (x2, y2) is the upper right corner, find the number of points inside the rectangle. Points on rectangle are considered inside.

Constraints : 1 ≤ N ≤ 100 000 1 ≤ Q ≤ 100 000 0 ≤ xi, yi ≤ 100 000 0 ≤ x1 < x2 ≤ 100 000 0 ≤ y1 < y2 ≤ 100 000

Does anyone have a link to this question or any implementation.

Thanks. DanceTheTragonDrainer.

  • Проголосовать: нравится
  • +14
  • Проголосовать: не нравится

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

Sort points by y coordinate and add them to fenwick tree by x coordinate. In fenwick tree store vectors of y coordinates. To get numbers of points in rectangle [0, x], [0, y] use upper_bound(v.begin(), v.end(), y) — v.begin(). If this is hard to understand use segment tree of segment trees.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +32 Проголосовать: не нравится

Good username.

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +8 Проголосовать: не нравится

A standard problem about the scanline with segment tree