#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const char nl = '\n';
void fastIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
bool intersect(int &x1, int &y1, int &x2, int &y2, int &r1, int &r2) {
ll dx = abs(x1 - x2);
ll dy = abs(y1 - y2);
ll dt = r1 + r2;
if (dt * dt >= dx * dx + dy * dy)
return true;
return false;
}
int main() {
fastIO();
int N;
cin>>N;
vector<pair<ii, int>> cr(N);
// {{x, y}, r}
set<pair<ii, ii>> all;
// {{r, -id}, {x, y}}
map<int, set<pair<int, ii>>> allx; // maps x coord to all {y, {r, id}}
for (int i = 0; i < N; i++) {
int x, y, r;
cin>>x>>y>>r;
all.insert({{r, -i}, {x, y}});
allx[x].insert({y, {r, i}});
}
vi par(N, -1);
int rem = N;
while (rem > 0) {
auto it = --all.end();
int r = (*it).fi.fi;
int id = -(*it).fi.se;
int x = (*it).se.fi;
int y = (*it).se.se;
// cout<<"at "<<id<<endl;
// consider all from x in x-2r to x+2r, y in y-2r to r+2r
int xl = max((ll)(x) - 2 * (ll)(r), (ll)(-2e9));
int xh = min((ll)(x) + 2 * (ll)(r), (ll)(2e9));
auto it2 = allx.lower_bound(xl);
while (it2 != allx.end() && (*it2).fi <= xh) {
// do another search inside
int cx = (*it2).fi;
vector<pair<ll, ii>> toremove;
int dx = abs(x - cx);
// can do up to sqrt for yh
ll dy = (ll)(pow(4 * (double)(r) * (double)(r) - (double)(dx) * (double)(dx), 0.5) + 1);
int yl = max((ll)(y) - dy, (ll)(-2e9));
int yh = min((ll)(y) + dy, (ll)(2e9));
auto it3 = allx[cx].lower_bound({yl, {-1, -1}});
while (it3 != allx[cx].end() && (*it3).fi <= yh) {
int cy = (*it3).fi;
int cr = (*it3).se.fi;
if (intersect(x, y, cx, cy, r, cr)) {
toremove.pb(*it3);
}
it3++;
}
for (pair<int, ii> p : toremove) {
par[p.se.se] = id;
// cout<<"erased "<<p.se.se<<endl;
allx[cx].erase(p);
all.erase({{p.se.fi, -p.se.se}, {cx, p.fi}});
rem--;
}
it2++;
}
}
// cout<<"ANSWER: ";
for (int x : par)
cout<<(x + 1)<<" ";
cout<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
5 ms |
1628 KB |
Output is correct |
20 |
Correct |
6 ms |
1532 KB |
Output is correct |
21 |
Correct |
7 ms |
1628 KB |
Output is correct |
22 |
Correct |
8 ms |
1632 KB |
Output is correct |
23 |
Correct |
32 ms |
1436 KB |
Output is correct |
24 |
Correct |
8 ms |
1628 KB |
Output is correct |
25 |
Correct |
6 ms |
1628 KB |
Output is correct |
26 |
Correct |
8 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
707 ms |
72988 KB |
Output is correct |
2 |
Correct |
744 ms |
73000 KB |
Output is correct |
3 |
Correct |
718 ms |
72672 KB |
Output is correct |
4 |
Correct |
720 ms |
72788 KB |
Output is correct |
5 |
Correct |
685 ms |
63488 KB |
Output is correct |
6 |
Correct |
707 ms |
72528 KB |
Output is correct |
7 |
Correct |
700 ms |
71012 KB |
Output is correct |
8 |
Correct |
725 ms |
71760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
689 ms |
24476 KB |
Output is correct |
3 |
Correct |
2615 ms |
72696 KB |
Output is correct |
4 |
Correct |
2522 ms |
72688 KB |
Output is correct |
5 |
Execution timed out |
3043 ms |
68740 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1512 ms |
72788 KB |
Output is correct |
2 |
Correct |
626 ms |
72632 KB |
Output is correct |
3 |
Execution timed out |
3083 ms |
70740 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
5 ms |
1628 KB |
Output is correct |
20 |
Correct |
6 ms |
1532 KB |
Output is correct |
21 |
Correct |
7 ms |
1628 KB |
Output is correct |
22 |
Correct |
8 ms |
1632 KB |
Output is correct |
23 |
Correct |
32 ms |
1436 KB |
Output is correct |
24 |
Correct |
8 ms |
1628 KB |
Output is correct |
25 |
Correct |
6 ms |
1628 KB |
Output is correct |
26 |
Correct |
8 ms |
1628 KB |
Output is correct |
27 |
Correct |
13 ms |
2652 KB |
Output is correct |
28 |
Correct |
12 ms |
2636 KB |
Output is correct |
29 |
Correct |
11 ms |
2652 KB |
Output is correct |
30 |
Correct |
33 ms |
2648 KB |
Output is correct |
31 |
Correct |
16 ms |
2652 KB |
Output is correct |
32 |
Correct |
16 ms |
2828 KB |
Output is correct |
33 |
Correct |
175 ms |
24376 KB |
Output is correct |
34 |
Correct |
155 ms |
24404 KB |
Output is correct |
35 |
Correct |
234 ms |
24400 KB |
Output is correct |
36 |
Correct |
277 ms |
24336 KB |
Output is correct |
37 |
Correct |
278 ms |
24664 KB |
Output is correct |
38 |
Correct |
379 ms |
24404 KB |
Output is correct |
39 |
Correct |
446 ms |
15020 KB |
Output is correct |
40 |
Correct |
438 ms |
14932 KB |
Output is correct |
41 |
Correct |
484 ms |
14928 KB |
Output is correct |
42 |
Correct |
155 ms |
15068 KB |
Output is correct |
43 |
Correct |
158 ms |
24404 KB |
Output is correct |
44 |
Correct |
158 ms |
24400 KB |
Output is correct |
45 |
Correct |
160 ms |
24404 KB |
Output is correct |
46 |
Correct |
156 ms |
24316 KB |
Output is correct |
47 |
Correct |
159 ms |
24660 KB |
Output is correct |
48 |
Correct |
172 ms |
24364 KB |
Output is correct |
49 |
Correct |
159 ms |
24404 KB |
Output is correct |
50 |
Correct |
169 ms |
24392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
5 ms |
1628 KB |
Output is correct |
20 |
Correct |
6 ms |
1532 KB |
Output is correct |
21 |
Correct |
7 ms |
1628 KB |
Output is correct |
22 |
Correct |
8 ms |
1632 KB |
Output is correct |
23 |
Correct |
32 ms |
1436 KB |
Output is correct |
24 |
Correct |
8 ms |
1628 KB |
Output is correct |
25 |
Correct |
6 ms |
1628 KB |
Output is correct |
26 |
Correct |
8 ms |
1628 KB |
Output is correct |
27 |
Correct |
707 ms |
72988 KB |
Output is correct |
28 |
Correct |
744 ms |
73000 KB |
Output is correct |
29 |
Correct |
718 ms |
72672 KB |
Output is correct |
30 |
Correct |
720 ms |
72788 KB |
Output is correct |
31 |
Correct |
685 ms |
63488 KB |
Output is correct |
32 |
Correct |
707 ms |
72528 KB |
Output is correct |
33 |
Correct |
700 ms |
71012 KB |
Output is correct |
34 |
Correct |
725 ms |
71760 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
689 ms |
24476 KB |
Output is correct |
37 |
Correct |
2615 ms |
72696 KB |
Output is correct |
38 |
Correct |
2522 ms |
72688 KB |
Output is correct |
39 |
Execution timed out |
3043 ms |
68740 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |