Luo Gu P4169 [Violet] angel doll / SJY put the pieces

%%% fairy \ (SJY \)

Subject to the effect:

A two-dimensional plane, there are two operations:

\ (1 \) Add a point \ ((x, y) \ )

\ (2 \) inquiry from \ ((x, y) \ ) Manhattan recent point how far

\ (N, m \ le 300 000, x_i, y_i \ the 1 million \)

Currently we do not \ (kd \ tree \) not to mention, and they talk about \ (cdq \) divide and conquer approach

If you consider a point in time to make a point at the top right, the Manhattan distance between two points can be converted into two points to the origin of the difference between the Manhattan distance, we can use this method to add \ (cdq \) partition obtained per a recent inquiry from the lower left corner of Manhattan

\ (cdq \) when the partition press \ (x \) sort by \ (y \) merge, according to \ (tim \) Fenwick tree could seconds

Then how do the other direction?

The whole matrix transpose three times, then run \ (4 \) times \ (cdq \) is not finished

Too lazy to put the code, quite bare of their own brain fill it

Guess you like

Origin www.cnblogs.com/knife-rose/p/12045557.html