2
void buildTree(vector<vector<int>> &p, int depth, int i, int j) {3
if (j - i <= 1) return;5
int k = 1 - depth & 1, m = i + (j - i) / 2;6
nth_element(p.begin() + i, p.begin() + m, p.begin() + j,7
[k](auto &a, auto &b) { return a[k] < b[k]; });8
partition(p.begin() + i, p.begin() + j, [k, m, &p](auto &a) { return a[k] < p[m][k]; });10
buildTree(p, depth + 1, i, m);11
buildTree(p, depth + 1, m + 1, j);14
inline bool isPointInside(const vector<int> &p, const vector<int> &c) {15
return (p[0] - c[0]) * (p[0] - c[0]) + (p[1] - c[1]) * (p[1] - c[1]) <= c[2] * c[2];18
int pointsInside(const vector<vector<int>> &t, const vector<int> &q, int depth, int i, int j) {22
return isPointInside(t[i], q);24
int k = 1 - depth & 1, m = i + (j - i) / 2, diff = t[m][k] - q[k];26
return pointsInside(t, q, depth + 1, i, m);27
else if (diff < -q[2])28
return pointsInside(t, q, depth + 1, m + 1, j);30
return pointsInside(t, q, depth + 1, i, m) + isPointInside(t[m], q) +31
pointsInside(t, q, depth + 1, m + 1, j);35
vector<int> countPoints(vector<vector<int>> &points, vector<vector<int>> &queries) {36
buildTree(points, 0, 0, points.size());38
vector<int> res(queries.size());39
for (size_t i = 0; i < queries.size(); ++i)40
res[i] = pointsInside(points, queries[i], 0, 0, points.size());