I have another geometry problem: N points on the plane are given and Q querys must be answered. Each query is about computing how many of those points lay inside a circunference. N,Q<=10^4
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 151 |
I have another geometry problem: N points on the plane are given and Q querys must be answered. Each query is about computing how many of those points lay inside a circunference. N,Q<=10^4
Name |
---|
There could be a lot of approaches — building sorted view of points by one or both coordinates, dividing set into square cells and then judging for each query which cells are enclosed completely etc.
Which variants you tried yourself and what difficulties you encountered?
I thought something like that but the problem is that the coordinates are x,y<=10^6
No problem, compress the coordinates, and divide the set into squares using the compressed ones. The other option is using a kd-tree to store the points, to answer the queries, each time you visit a node check if its bounds cut the circle (if not exit the subtree), or if it is completely contained whitin it, then continue exploring the subtree or add all the points on the subtree.
In the given constraints (N, Q <= 10^4 ) stupid solution O(Q * N) can be fast enough, don't use square root operation, compare squares of the distances.
I already try that but I got tle