#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
const double eps = 1e-9;
struct poi{
int x, y, r;
};
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<poi> a(n);
vector<vector<ar<int, 2>>> pp;
vector<int> used(n), tot, par(n);
int R;
auto get = [&](int x){
if(x >= 0) return x / R;
else {
return (x + 1) / R - 1;
}
};
auto rec = [&](){
pp.clear(); tot.clear();
for(int i=0;i<n;i++) {
if(used[i]) continue;
tot.push_back(get(a[i].x));
}
sort(tot.begin(), tot.end());
tot.erase(unique(tot.begin(), tot.end()), tot.end());
pp.resize(tot.size());
for(int i=0;i<n;i++){
if(used[i]) continue;
auto j = lower_bound(tot.begin(), tot.end(), get(a[i].x)) - tot.begin();
//~ assert(j < (int)tot.size());
pp[j].push_back({a[i].y, i});
}
for(int i=0;i<(int)tot.size();i++){
sort(pp[i].begin(), pp[i].end());
for(int j=0;j<(int)pp[i].size();j++){
par[pp[i][j][1]] = j + 1;
}
}
};
vector<int> p(n);
for(int i=0;i<n;i++){
p[i] = i;
cin>>a[i].x>>a[i].y>>a[i].r;
}
sort(p.begin(), p.end(), [&](int i, int j){
if(a[i].r != a[j].r)
return (a[i].r > a[j].r);
else
return i < j;
});
auto sq = [&](int x) { return x * 1ll * x; };
auto dis = [&](int i, int j) -> double{
return sqrt(sq(a[i].x - a[j].x) + sq(a[i].y - a[j].y));
};
auto check = [&](int i, int j){
return (a[i].r + a[j].r >= dis(i, j));
};
R = a[p[0]].r;
rec();
for(auto i : p){
if(used[i]) continue;
if(a[i].r * 2 <= R) R = a[i].r, rec();
int l = lower_bound(tot.begin(), tot.end(), get(a[i].x) - 2) - tot.begin();
int r = upper_bound(tot.begin(), tot.end(), get(a[i].x) + 2) - tot.begin();
int lx = (get(a[i].y) - 2) * R;
int rx = (get(a[i].y) + 3) * R;
function<int(int, int)> f = [&](int j, int i){
if(i >= (int)pp[j].size() || !used[pp[j][i][1]]) return i;
par[pp[j][i][1]] = f(j, par[pp[j][i][1]]);
return par[pp[j][i][1]];
};
for(int j=l;j<r;j++){
int it = lower_bound(pp[j].begin(), pp[j].end(), (ar<int, 2>){lx, -1}) - pp[j].begin();
while(it < (int)pp[j].size() && pp[j][it][0] < rx){
if(check(pp[j][it][1], i)){
used[pp[j][it][1]] = i + 1;
}
it = par[pp[j][it][1]];
it = f(j, it);
}
}
}
for(int i=0;i<n;i++) cout<<used[i]<<" ";
cout<<"\n";
}
/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
392 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
980 KB |
Output is correct |
20 |
Correct |
3 ms |
980 KB |
Output is correct |
21 |
Correct |
3 ms |
980 KB |
Output is correct |
22 |
Correct |
6 ms |
928 KB |
Output is correct |
23 |
Correct |
6 ms |
852 KB |
Output is correct |
24 |
Correct |
6 ms |
980 KB |
Output is correct |
25 |
Correct |
6 ms |
976 KB |
Output is correct |
26 |
Correct |
8 ms |
952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
26012 KB |
Output is correct |
2 |
Incorrect |
182 ms |
28236 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
145 ms |
9992 KB |
Output is correct |
3 |
Correct |
550 ms |
28176 KB |
Output is correct |
4 |
Correct |
549 ms |
28884 KB |
Output is correct |
5 |
Correct |
512 ms |
25920 KB |
Output is correct |
6 |
Correct |
195 ms |
13908 KB |
Output is correct |
7 |
Correct |
95 ms |
7896 KB |
Output is correct |
8 |
Correct |
17 ms |
2256 KB |
Output is correct |
9 |
Correct |
574 ms |
27228 KB |
Output is correct |
10 |
Correct |
467 ms |
25708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
429 ms |
29424 KB |
Output is correct |
2 |
Correct |
369 ms |
35640 KB |
Output is correct |
3 |
Incorrect |
261 ms |
25588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
392 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
980 KB |
Output is correct |
20 |
Correct |
3 ms |
980 KB |
Output is correct |
21 |
Correct |
3 ms |
980 KB |
Output is correct |
22 |
Correct |
6 ms |
928 KB |
Output is correct |
23 |
Correct |
6 ms |
852 KB |
Output is correct |
24 |
Correct |
6 ms |
980 KB |
Output is correct |
25 |
Correct |
6 ms |
976 KB |
Output is correct |
26 |
Correct |
8 ms |
952 KB |
Output is correct |
27 |
Correct |
7 ms |
1484 KB |
Output is correct |
28 |
Correct |
6 ms |
1492 KB |
Output is correct |
29 |
Correct |
7 ms |
1364 KB |
Output is correct |
30 |
Correct |
12 ms |
1500 KB |
Output is correct |
31 |
Correct |
12 ms |
1540 KB |
Output is correct |
32 |
Correct |
15 ms |
1592 KB |
Output is correct |
33 |
Correct |
70 ms |
8352 KB |
Output is correct |
34 |
Correct |
66 ms |
9108 KB |
Output is correct |
35 |
Incorrect |
71 ms |
10392 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
392 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
980 KB |
Output is correct |
20 |
Correct |
3 ms |
980 KB |
Output is correct |
21 |
Correct |
3 ms |
980 KB |
Output is correct |
22 |
Correct |
6 ms |
928 KB |
Output is correct |
23 |
Correct |
6 ms |
852 KB |
Output is correct |
24 |
Correct |
6 ms |
980 KB |
Output is correct |
25 |
Correct |
6 ms |
976 KB |
Output is correct |
26 |
Correct |
8 ms |
952 KB |
Output is correct |
27 |
Correct |
179 ms |
26012 KB |
Output is correct |
28 |
Incorrect |
182 ms |
28236 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |