#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
struct hashFunc{
size_t operator()(const pl& a) const {
return a.f^(a.s+1);
}
};
const int mx = 300005;
int n;
ll x[mx];
ll y[mx];
ll r[mx];
bool circIntersect(int a, int b){
ll dist_sq = (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
if(dist_sq <= (r[a]+r[b])*(r[a]+r[b])){
return true;
}
return false;
}
vector<pair<ll, int>> buckets[35];
int ans[mx];
gp_hash_table<pl, vi, hashFunc> g;
ll GRID;
ll fdiv(ll a, ll b){
assert(b >= 1);
if(a >= 0) return a/b;
return (a+1)/b-1;
}
pl gridReduce(pl a){
return mp(fdiv(a.f, GRID), fdiv(a.s, GRID));
}
void remDup(vpl& a){
sort(all(a));
a.erase(unique(all(a)), a.end());
}
vpl getCorners(int circ){
vpl corners = vpl{mp(x[circ]+r[circ], y[circ]+r[circ]), mp(x[circ]-r[circ], y[circ]+r[circ]), mp(x[circ]-r[circ], y[circ]-r[circ]), mp(x[circ]+r[circ], y[circ]-r[circ])};
vector<pl> res;
for(auto u: corners){
res.pb(gridReduce(u));
}
remDup(res);
return res;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i] >> r[i];
}
for(int i = 1; i <= n; i++){
for(int j = 0; j < 35; j++){
if(r[i] < (1LL<<j)){
buckets[j-1].pb(mp(-r[i], i));
break;
}
}
}
assert(sz(buckets[30]) == 0);
for(int k = 29; k >= 0; k--){
sort(all(buckets[k]));
g.clear();
GRID = (1LL<<(k+2));
for(int i = 1; i <= n; i++){
if(ans[i] == 0){
for(auto u: getCorners(i)){
g[u].pb(i);
}
}
}
for(auto circ: buckets[k]){
int ind = circ.s;
if(ans[ind] == 0){
for(auto u: getCorners(ind)){
vi new_cands;
for(auto cand: g[u]){
if(ans[cand] != 0) continue;
if(circIntersect(ind, cand)){
ans[cand] = ind;
}
else{
new_cands.pb(cand);
}
}
g[u] = new_cands;
}
assert(ans[ind] == ind);
}
}
}
for(int i = 1; i <= n; i++){
cout << ans[i] << " ";
}
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
6 ms |
844 KB |
Output is correct |
20 |
Correct |
6 ms |
844 KB |
Output is correct |
21 |
Correct |
5 ms |
716 KB |
Output is correct |
22 |
Correct |
127 ms |
3632 KB |
Output is correct |
23 |
Correct |
66 ms |
3792 KB |
Output is correct |
24 |
Correct |
173 ms |
3900 KB |
Output is correct |
25 |
Correct |
164 ms |
3640 KB |
Output is correct |
26 |
Correct |
149 ms |
3592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
334 ms |
21864 KB |
Output is correct |
2 |
Correct |
403 ms |
21304 KB |
Output is correct |
3 |
Correct |
397 ms |
21192 KB |
Output is correct |
4 |
Correct |
269 ms |
21688 KB |
Output is correct |
5 |
Execution timed out |
3015 ms |
20016 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Execution timed out |
3053 ms |
14236 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3066 ms |
25160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
6 ms |
844 KB |
Output is correct |
20 |
Correct |
6 ms |
844 KB |
Output is correct |
21 |
Correct |
5 ms |
716 KB |
Output is correct |
22 |
Correct |
127 ms |
3632 KB |
Output is correct |
23 |
Correct |
66 ms |
3792 KB |
Output is correct |
24 |
Correct |
173 ms |
3900 KB |
Output is correct |
25 |
Correct |
164 ms |
3640 KB |
Output is correct |
26 |
Correct |
149 ms |
3592 KB |
Output is correct |
27 |
Correct |
12 ms |
1336 KB |
Output is correct |
28 |
Correct |
13 ms |
1252 KB |
Output is correct |
29 |
Correct |
11 ms |
1204 KB |
Output is correct |
30 |
Correct |
502 ms |
6960 KB |
Output is correct |
31 |
Correct |
1678 ms |
7144 KB |
Output is correct |
32 |
Correct |
638 ms |
7176 KB |
Output is correct |
33 |
Correct |
92 ms |
9328 KB |
Output is correct |
34 |
Correct |
92 ms |
9996 KB |
Output is correct |
35 |
Correct |
128 ms |
9304 KB |
Output is correct |
36 |
Execution timed out |
3052 ms |
13948 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
6 ms |
844 KB |
Output is correct |
20 |
Correct |
6 ms |
844 KB |
Output is correct |
21 |
Correct |
5 ms |
716 KB |
Output is correct |
22 |
Correct |
127 ms |
3632 KB |
Output is correct |
23 |
Correct |
66 ms |
3792 KB |
Output is correct |
24 |
Correct |
173 ms |
3900 KB |
Output is correct |
25 |
Correct |
164 ms |
3640 KB |
Output is correct |
26 |
Correct |
149 ms |
3592 KB |
Output is correct |
27 |
Correct |
334 ms |
21864 KB |
Output is correct |
28 |
Correct |
403 ms |
21304 KB |
Output is correct |
29 |
Correct |
397 ms |
21192 KB |
Output is correct |
30 |
Correct |
269 ms |
21688 KB |
Output is correct |
31 |
Execution timed out |
3015 ms |
20016 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |