/*
Simulate process by checking all circles whose centre is in square of width 4*r. Use a kd-tree for this.
*/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define cerr cout
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
const int N = 3e5 + 10;
vi x, y, r;
struct node {
int l, r, sum, mid;
int aid;
node(): l(0), r(0), sum(0), mid(0), aid(0) {}
};
vector<node> T;
vector<vector<int>> A;
vi xc, yc;
vi par;
inline bool intersect(int i, int j) {
return (x[i] - x[j]) * 1LL * (x[i] - x[j]) + (y[i] - y[j]) * 1LL * (y[i] - y[j]) <= (r[i] + r[j]) * 1LL * (r[i] + r[j]);
}
inline int make_node() {
T.emplace_back();
return sz(T) - 1;
}
int build(int no, bool dim, int xl, int xr, int yl, int yr, const vi& ids) {
if (xr < xl or yr < yl) return no;
if (ids.empty()) return no;
if (no == 0) no = make_node();
bool g = 1;
FOR (i, 1, sz(ids) - 1) if (x[ids[i]] != x[ids[0]] or y[ids[i]] != y[ids[0]]) {g = 0; break;}
if (g) {
T[no].sum = sz(ids);
A.emplace_back(ids);
T[no].aid = sz(A)-1;
return no;
}
if (dim) {
int mid = yl == yr ? yl : (rand() % (yr-yl) + yl);
vi lids, rids;
for (int it : ids) {
if (y[it] <= yc[mid]) lids.emplace_back(it);
else rids.emplace_back(it);
}
int L = build(0, 0, xl, xr, yl, mid, lids);
int R = build(0, 0, xl, xr, mid + 1, yr, rids);
T[no].l = L, T[no].r = R;
T[no].sum = T[T[no].l].sum + T[T[no].r].sum;
T[no].mid = mid;
} else {
int mid = xl==xr ? xl : (rand() % (xr-xl) + xl);
vi lids, rids;
for (int it : ids) {
if (x[it] <= xc[mid]) lids.emplace_back(it);
else rids.emplace_back(it);
}
int L = build(0, 1, xl, mid, yl, yr, lids);
int R = build(0, 1, mid + 1, xr, yl, yr, rids);
T[no].l = L, T[no].r = R;
T[no].sum = T[T[no].l].sum + T[T[no].r].sum;
T[no].mid = mid;
}
return no;
}
int xu, xv, yu, yv, bc;
vi rem;
void get(int no, bool dim, int xl, int xr, int yl, int yr) {
if (T[no].sum == 0) return;
if (xr < xu or xl > xv) return;
if (yr < yu or yl > yv) return;
if (T[no].l == 0 and T[no].r == 0) {
for (int it: A[T[no].aid]) if (intersect(it, bc)) {
par[it] = bc;
rem.emplace_back(it);
T[no].sum--;
}
reverse(all(rem));
vi& a = A[T[no].aid];
int j = 0;
FOR (i, 0, sz(a) - 1) {
if (rem.empty() or a[i] != rem.back()) {
a[j] = a[i];
++j;
} else {
rem.pop_back();
}
}
a.resize(j);
rem.clear();
return;
}
if (dim) {
int mid = T[no].mid;
get(T[no].l, 0, xl,xr,yl, mid);
get(T[no].r, 0, xl, xr, mid+1, yr);
T[no].sum = T[T[no].l].sum + T[T[no].r].sum;
} else {
int mid = T[no].mid;
get(T[no].l, 1, xl, mid, yl, yr);
get(T[no].r, 1, mid+1, xr, yl, yr);
T[no].sum = T[T[no].l].sum + T[T[no].r].sum;
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
x.resize(n), y.resize(n), r.resize(n);
par = vi(n, -1);
FOR (i, 0, n - 1) {
cin >> x[i] >> y[i] >> r[i];
xc.emplace_back(x[i]);
yc.emplace_back(y[i]);
}
xc.emplace_back(-inf), xc.emplace_back(inf);
yc.emplace_back(-inf), yc.emplace_back(inf);
sort(all(xc)); xc.erase(unique(all(xc)), xc.end());
sort(all(yc)); yc.erase(unique(all(yc)), yc.end());
vi id(n); iota(all(id), 0);
sort(all(id), [&](int x, int y) {
if (r[x] == r[y]) return x < y;
return r[x] > r[y];
});
T.reserve(2e7);
T.emplace_back();
int root = build(0, 0, 0, sz(xc)-1, 0, sz(yc)-1, id);
for (int i : id) if (par[i] == -1) {
bc = i;
xu = max(x[i] - 2LL * r[i], (ll) - inf);
xu = lower_bound(all(xc), xu) - xc.begin();
xv = min(x[i] + 2LL * r[i], (ll)inf);
xv = upper_bound(all(xc), xv) - xc.begin()-1;
yu = max(y[i] - 2LL * r[i], (ll) - 1e9);
yu = lower_bound(all(yc), yu) - yc.begin();
yv = min(y[i] + 2LL * r[i], (ll)1e9);
yv = upper_bound(all(yc), yv) - yc.begin()-1;
get(root, 0, 0, sz(xc)-1, 0, sz(yc)-1);
}
FOR (i, 0, n - 1) cout << par[i] + 1 << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
9 ms |
1400 KB |
Output is correct |
20 |
Correct |
9 ms |
1404 KB |
Output is correct |
21 |
Correct |
9 ms |
1400 KB |
Output is correct |
22 |
Correct |
12 ms |
1276 KB |
Output is correct |
23 |
Correct |
13 ms |
1272 KB |
Output is correct |
24 |
Correct |
12 ms |
1400 KB |
Output is correct |
25 |
Correct |
12 ms |
1400 KB |
Output is correct |
26 |
Correct |
12 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
547 ms |
50584 KB |
Output is correct |
2 |
Correct |
638 ms |
52992 KB |
Output is correct |
3 |
Correct |
612 ms |
55848 KB |
Output is correct |
4 |
Correct |
659 ms |
57660 KB |
Output is correct |
5 |
Correct |
503 ms |
41820 KB |
Output is correct |
6 |
Correct |
848 ms |
53268 KB |
Output is correct |
7 |
Correct |
649 ms |
51156 KB |
Output is correct |
8 |
Correct |
705 ms |
50924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
573 ms |
16132 KB |
Output is correct |
3 |
Correct |
1364 ms |
49064 KB |
Output is correct |
4 |
Correct |
1367 ms |
47696 KB |
Output is correct |
5 |
Correct |
1391 ms |
54076 KB |
Output is correct |
6 |
Correct |
584 ms |
32984 KB |
Output is correct |
7 |
Correct |
264 ms |
18272 KB |
Output is correct |
8 |
Correct |
53 ms |
4660 KB |
Output is correct |
9 |
Correct |
1509 ms |
51876 KB |
Output is correct |
10 |
Correct |
1027 ms |
54284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1050 ms |
47680 KB |
Output is correct |
2 |
Correct |
1051 ms |
48296 KB |
Output is correct |
3 |
Correct |
723 ms |
47332 KB |
Output is correct |
4 |
Correct |
1034 ms |
48124 KB |
Output is correct |
5 |
Correct |
1152 ms |
48668 KB |
Output is correct |
6 |
Correct |
716 ms |
48180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
9 ms |
1400 KB |
Output is correct |
20 |
Correct |
9 ms |
1404 KB |
Output is correct |
21 |
Correct |
9 ms |
1400 KB |
Output is correct |
22 |
Correct |
12 ms |
1276 KB |
Output is correct |
23 |
Correct |
13 ms |
1272 KB |
Output is correct |
24 |
Correct |
12 ms |
1400 KB |
Output is correct |
25 |
Correct |
12 ms |
1400 KB |
Output is correct |
26 |
Correct |
12 ms |
1400 KB |
Output is correct |
27 |
Correct |
16 ms |
2100 KB |
Output is correct |
28 |
Correct |
17 ms |
2104 KB |
Output is correct |
29 |
Correct |
17 ms |
2168 KB |
Output is correct |
30 |
Correct |
28 ms |
2176 KB |
Output is correct |
31 |
Correct |
27 ms |
2168 KB |
Output is correct |
32 |
Correct |
27 ms |
2100 KB |
Output is correct |
33 |
Correct |
164 ms |
16352 KB |
Output is correct |
34 |
Correct |
203 ms |
16328 KB |
Output is correct |
35 |
Correct |
188 ms |
16132 KB |
Output is correct |
36 |
Correct |
416 ms |
15884 KB |
Output is correct |
37 |
Correct |
356 ms |
16052 KB |
Output is correct |
38 |
Correct |
389 ms |
16144 KB |
Output is correct |
39 |
Correct |
1147 ms |
14768 KB |
Output is correct |
40 |
Correct |
1002 ms |
15452 KB |
Output is correct |
41 |
Correct |
982 ms |
14788 KB |
Output is correct |
42 |
Correct |
175 ms |
16300 KB |
Output is correct |
43 |
Correct |
328 ms |
17452 KB |
Output is correct |
44 |
Correct |
328 ms |
17184 KB |
Output is correct |
45 |
Correct |
419 ms |
17300 KB |
Output is correct |
46 |
Correct |
325 ms |
17088 KB |
Output is correct |
47 |
Correct |
392 ms |
17836 KB |
Output is correct |
48 |
Correct |
351 ms |
17320 KB |
Output is correct |
49 |
Correct |
356 ms |
17248 KB |
Output is correct |
50 |
Correct |
371 ms |
16704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
9 ms |
1400 KB |
Output is correct |
20 |
Correct |
9 ms |
1404 KB |
Output is correct |
21 |
Correct |
9 ms |
1400 KB |
Output is correct |
22 |
Correct |
12 ms |
1276 KB |
Output is correct |
23 |
Correct |
13 ms |
1272 KB |
Output is correct |
24 |
Correct |
12 ms |
1400 KB |
Output is correct |
25 |
Correct |
12 ms |
1400 KB |
Output is correct |
26 |
Correct |
12 ms |
1400 KB |
Output is correct |
27 |
Correct |
547 ms |
50584 KB |
Output is correct |
28 |
Correct |
638 ms |
52992 KB |
Output is correct |
29 |
Correct |
612 ms |
55848 KB |
Output is correct |
30 |
Correct |
659 ms |
57660 KB |
Output is correct |
31 |
Correct |
503 ms |
41820 KB |
Output is correct |
32 |
Correct |
848 ms |
53268 KB |
Output is correct |
33 |
Correct |
649 ms |
51156 KB |
Output is correct |
34 |
Correct |
705 ms |
50924 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
573 ms |
16132 KB |
Output is correct |
37 |
Correct |
1364 ms |
49064 KB |
Output is correct |
38 |
Correct |
1367 ms |
47696 KB |
Output is correct |
39 |
Correct |
1391 ms |
54076 KB |
Output is correct |
40 |
Correct |
584 ms |
32984 KB |
Output is correct |
41 |
Correct |
264 ms |
18272 KB |
Output is correct |
42 |
Correct |
53 ms |
4660 KB |
Output is correct |
43 |
Correct |
1509 ms |
51876 KB |
Output is correct |
44 |
Correct |
1027 ms |
54284 KB |
Output is correct |
45 |
Correct |
1050 ms |
47680 KB |
Output is correct |
46 |
Correct |
1051 ms |
48296 KB |
Output is correct |
47 |
Correct |
723 ms |
47332 KB |
Output is correct |
48 |
Correct |
1034 ms |
48124 KB |
Output is correct |
49 |
Correct |
1152 ms |
48668 KB |
Output is correct |
50 |
Correct |
716 ms |
48180 KB |
Output is correct |
51 |
Correct |
16 ms |
2100 KB |
Output is correct |
52 |
Correct |
17 ms |
2104 KB |
Output is correct |
53 |
Correct |
17 ms |
2168 KB |
Output is correct |
54 |
Correct |
28 ms |
2176 KB |
Output is correct |
55 |
Correct |
27 ms |
2168 KB |
Output is correct |
56 |
Correct |
27 ms |
2100 KB |
Output is correct |
57 |
Correct |
164 ms |
16352 KB |
Output is correct |
58 |
Correct |
203 ms |
16328 KB |
Output is correct |
59 |
Correct |
188 ms |
16132 KB |
Output is correct |
60 |
Correct |
416 ms |
15884 KB |
Output is correct |
61 |
Correct |
356 ms |
16052 KB |
Output is correct |
62 |
Correct |
389 ms |
16144 KB |
Output is correct |
63 |
Correct |
1147 ms |
14768 KB |
Output is correct |
64 |
Correct |
1002 ms |
15452 KB |
Output is correct |
65 |
Correct |
982 ms |
14788 KB |
Output is correct |
66 |
Correct |
175 ms |
16300 KB |
Output is correct |
67 |
Correct |
328 ms |
17452 KB |
Output is correct |
68 |
Correct |
328 ms |
17184 KB |
Output is correct |
69 |
Correct |
419 ms |
17300 KB |
Output is correct |
70 |
Correct |
325 ms |
17088 KB |
Output is correct |
71 |
Correct |
392 ms |
17836 KB |
Output is correct |
72 |
Correct |
351 ms |
17320 KB |
Output is correct |
73 |
Correct |
356 ms |
17248 KB |
Output is correct |
74 |
Correct |
371 ms |
16704 KB |
Output is correct |
75 |
Correct |
611 ms |
50024 KB |
Output is correct |
76 |
Correct |
653 ms |
50276 KB |
Output is correct |
77 |
Correct |
541 ms |
50472 KB |
Output is correct |
78 |
Correct |
627 ms |
49432 KB |
Output is correct |
79 |
Correct |
713 ms |
48740 KB |
Output is correct |
80 |
Correct |
598 ms |
48632 KB |
Output is correct |
81 |
Correct |
1195 ms |
49280 KB |
Output is correct |
82 |
Correct |
1598 ms |
49256 KB |
Output is correct |
83 |
Correct |
1477 ms |
48948 KB |
Output is correct |
84 |
Correct |
1591 ms |
48020 KB |
Output is correct |
85 |
Correct |
1531 ms |
50516 KB |
Output is correct |
86 |
Correct |
1344 ms |
49288 KB |
Output is correct |
87 |
Correct |
1383 ms |
49100 KB |
Output is correct |
88 |
Execution timed out |
3019 ms |
44492 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |