// Null
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll Mod = 1000000007LL;
const int N = 3e5 + 10;
const int Inf = 2e9;
int n, x[N], y[N], r[N];
int mk[N];
vector<pii> V[N];
vector<int> U, X, Y;
void Build(int L){
for(int i = 0; i < (int) U.size(); i++) V[i].clear();
U.clear();
for(int i : X){
if(mk[i]) continue;
U.pb(x[i] / L);
}
//sort(all(U));
U.resize(unique(all(U)) - U.begin() );
for(int i : Y)
if(!mk[i])
V[lower_bound(all(U), x[i] / L) - U.begin()].pb({y[i] / L, i});
for(int i = 0; i < (int) U.size(); i++)
sort(all(V[i]));
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i] >> r[i];
X.pb(i);
Y.pb(i);
}
vector<int> I(n); iota(all(I), 1);
sort(all(I), [&](int i, int j){
return (r[i] == r[j] ? i < j : r[i] > r[j]);
});
sort(all(X), [&](int i, int j){
return x[i] < x[j];
});
sort(all(Y), [&](int i, int j){
return y[i] < y[j];
});
int L = r[I[0]];
Build(L);
for(auto id : I){
if(mk[id]) continue;
if(L*3 >= 4*r[id]) Build(L = r[id]);
int i = x[id] / L;
int j = y[id] / L;
int nei;
for(int pos = lower_bound(all(U), i - 2) - U.begin(); pos < (int) U.size() && U[pos] <= i + 2; pos ++){
for(int posj = lower_bound(all(V[pos]), pii(j - 2, -1)) - V[pos].begin(); posj < (int) V[pos].size() && V[pos][posj].F <= j + 2; posj ++){
nei = V[pos][posj].S;
if(mk[nei]) continue;
if(1ll*(x[id] - x[nei])*(x[id] - x[nei]) + 1ll*(y[id] - y[nei])*(y[id] - y[nei]) <= 1ll*(r[id] + r[nei])*(r[id] + r[nei]) ){
mk[nei] = id;
}
}
}
}
for(int i = 1; i <= n; i++) cout << mk[i] << ' ';
cout << '\n';
return 0;
}
/*
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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
6 ms |
7552 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
6 ms |
7424 KB |
Output is correct |
6 |
Correct |
6 ms |
7424 KB |
Output is correct |
7 |
Correct |
6 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
6 ms |
7424 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
11 |
Correct |
5 ms |
7424 KB |
Output is correct |
12 |
Correct |
5 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
5 ms |
7424 KB |
Output is correct |
15 |
Correct |
5 ms |
7424 KB |
Output is correct |
16 |
Correct |
7 ms |
7424 KB |
Output is correct |
17 |
Correct |
5 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7424 KB |
Output is correct |
19 |
Correct |
9 ms |
7680 KB |
Output is correct |
20 |
Correct |
9 ms |
7680 KB |
Output is correct |
21 |
Correct |
9 ms |
7680 KB |
Output is correct |
22 |
Correct |
12 ms |
7808 KB |
Output is correct |
23 |
Correct |
12 ms |
7680 KB |
Output is correct |
24 |
Correct |
12 ms |
7680 KB |
Output is correct |
25 |
Correct |
12 ms |
7808 KB |
Output is correct |
26 |
Correct |
12 ms |
7768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
257 ms |
21444 KB |
Output is correct |
2 |
Correct |
242 ms |
22600 KB |
Output is correct |
3 |
Correct |
236 ms |
23500 KB |
Output is correct |
4 |
Correct |
237 ms |
21352 KB |
Output is correct |
5 |
Correct |
284 ms |
22476 KB |
Output is correct |
6 |
Correct |
433 ms |
29268 KB |
Output is correct |
7 |
Correct |
307 ms |
27856 KB |
Output is correct |
8 |
Correct |
322 ms |
27732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7424 KB |
Output is correct |
2 |
Correct |
197 ms |
13032 KB |
Output is correct |
3 |
Correct |
728 ms |
32680 KB |
Output is correct |
4 |
Correct |
758 ms |
32664 KB |
Output is correct |
5 |
Correct |
654 ms |
33280 KB |
Output is correct |
6 |
Correct |
267 ms |
20832 KB |
Output is correct |
7 |
Correct |
133 ms |
14316 KB |
Output is correct |
8 |
Correct |
28 ms |
8952 KB |
Output is correct |
9 |
Correct |
842 ms |
35148 KB |
Output is correct |
10 |
Correct |
606 ms |
34380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
458 ms |
23608 KB |
Output is correct |
2 |
Correct |
501 ms |
35408 KB |
Output is correct |
3 |
Correct |
307 ms |
30296 KB |
Output is correct |
4 |
Correct |
518 ms |
34900 KB |
Output is correct |
5 |
Correct |
488 ms |
35412 KB |
Output is correct |
6 |
Correct |
290 ms |
29392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
6 ms |
7552 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
6 ms |
7424 KB |
Output is correct |
6 |
Correct |
6 ms |
7424 KB |
Output is correct |
7 |
Correct |
6 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
6 ms |
7424 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
11 |
Correct |
5 ms |
7424 KB |
Output is correct |
12 |
Correct |
5 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
5 ms |
7424 KB |
Output is correct |
15 |
Correct |
5 ms |
7424 KB |
Output is correct |
16 |
Correct |
7 ms |
7424 KB |
Output is correct |
17 |
Correct |
5 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7424 KB |
Output is correct |
19 |
Correct |
9 ms |
7680 KB |
Output is correct |
20 |
Correct |
9 ms |
7680 KB |
Output is correct |
21 |
Correct |
9 ms |
7680 KB |
Output is correct |
22 |
Correct |
12 ms |
7808 KB |
Output is correct |
23 |
Correct |
12 ms |
7680 KB |
Output is correct |
24 |
Correct |
12 ms |
7680 KB |
Output is correct |
25 |
Correct |
12 ms |
7808 KB |
Output is correct |
26 |
Correct |
12 ms |
7768 KB |
Output is correct |
27 |
Correct |
13 ms |
7936 KB |
Output is correct |
28 |
Correct |
12 ms |
7936 KB |
Output is correct |
29 |
Correct |
16 ms |
7936 KB |
Output is correct |
30 |
Correct |
20 ms |
7936 KB |
Output is correct |
31 |
Correct |
20 ms |
7936 KB |
Output is correct |
32 |
Correct |
20 ms |
8064 KB |
Output is correct |
33 |
Correct |
111 ms |
12140 KB |
Output is correct |
34 |
Correct |
99 ms |
12264 KB |
Output is correct |
35 |
Correct |
106 ms |
12392 KB |
Output is correct |
36 |
Correct |
201 ms |
13092 KB |
Output is correct |
37 |
Correct |
213 ms |
15720 KB |
Output is correct |
38 |
Correct |
203 ms |
15724 KB |
Output is correct |
39 |
Correct |
478 ms |
15056 KB |
Output is correct |
40 |
Correct |
451 ms |
15064 KB |
Output is correct |
41 |
Correct |
461 ms |
15056 KB |
Output is correct |
42 |
Correct |
94 ms |
14060 KB |
Output is correct |
43 |
Correct |
121 ms |
16872 KB |
Output is correct |
44 |
Correct |
121 ms |
16744 KB |
Output is correct |
45 |
Correct |
125 ms |
16748 KB |
Output is correct |
46 |
Correct |
119 ms |
16748 KB |
Output is correct |
47 |
Correct |
114 ms |
16748 KB |
Output is correct |
48 |
Correct |
118 ms |
16744 KB |
Output is correct |
49 |
Correct |
116 ms |
16744 KB |
Output is correct |
50 |
Correct |
114 ms |
16732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
6 ms |
7552 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
6 ms |
7424 KB |
Output is correct |
6 |
Correct |
6 ms |
7424 KB |
Output is correct |
7 |
Correct |
6 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
6 ms |
7424 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
11 |
Correct |
5 ms |
7424 KB |
Output is correct |
12 |
Correct |
5 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
5 ms |
7424 KB |
Output is correct |
15 |
Correct |
5 ms |
7424 KB |
Output is correct |
16 |
Correct |
7 ms |
7424 KB |
Output is correct |
17 |
Correct |
5 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7424 KB |
Output is correct |
19 |
Correct |
9 ms |
7680 KB |
Output is correct |
20 |
Correct |
9 ms |
7680 KB |
Output is correct |
21 |
Correct |
9 ms |
7680 KB |
Output is correct |
22 |
Correct |
12 ms |
7808 KB |
Output is correct |
23 |
Correct |
12 ms |
7680 KB |
Output is correct |
24 |
Correct |
12 ms |
7680 KB |
Output is correct |
25 |
Correct |
12 ms |
7808 KB |
Output is correct |
26 |
Correct |
12 ms |
7768 KB |
Output is correct |
27 |
Correct |
257 ms |
21444 KB |
Output is correct |
28 |
Correct |
242 ms |
22600 KB |
Output is correct |
29 |
Correct |
236 ms |
23500 KB |
Output is correct |
30 |
Correct |
237 ms |
21352 KB |
Output is correct |
31 |
Correct |
284 ms |
22476 KB |
Output is correct |
32 |
Correct |
433 ms |
29268 KB |
Output is correct |
33 |
Correct |
307 ms |
27856 KB |
Output is correct |
34 |
Correct |
322 ms |
27732 KB |
Output is correct |
35 |
Correct |
4 ms |
7424 KB |
Output is correct |
36 |
Correct |
197 ms |
13032 KB |
Output is correct |
37 |
Correct |
728 ms |
32680 KB |
Output is correct |
38 |
Correct |
758 ms |
32664 KB |
Output is correct |
39 |
Correct |
654 ms |
33280 KB |
Output is correct |
40 |
Correct |
267 ms |
20832 KB |
Output is correct |
41 |
Correct |
133 ms |
14316 KB |
Output is correct |
42 |
Correct |
28 ms |
8952 KB |
Output is correct |
43 |
Correct |
842 ms |
35148 KB |
Output is correct |
44 |
Correct |
606 ms |
34380 KB |
Output is correct |
45 |
Correct |
458 ms |
23608 KB |
Output is correct |
46 |
Correct |
501 ms |
35408 KB |
Output is correct |
47 |
Correct |
307 ms |
30296 KB |
Output is correct |
48 |
Correct |
518 ms |
34900 KB |
Output is correct |
49 |
Correct |
488 ms |
35412 KB |
Output is correct |
50 |
Correct |
290 ms |
29392 KB |
Output is correct |
51 |
Correct |
13 ms |
7936 KB |
Output is correct |
52 |
Correct |
12 ms |
7936 KB |
Output is correct |
53 |
Correct |
16 ms |
7936 KB |
Output is correct |
54 |
Correct |
20 ms |
7936 KB |
Output is correct |
55 |
Correct |
20 ms |
7936 KB |
Output is correct |
56 |
Correct |
20 ms |
8064 KB |
Output is correct |
57 |
Correct |
111 ms |
12140 KB |
Output is correct |
58 |
Correct |
99 ms |
12264 KB |
Output is correct |
59 |
Correct |
106 ms |
12392 KB |
Output is correct |
60 |
Correct |
201 ms |
13092 KB |
Output is correct |
61 |
Correct |
213 ms |
15720 KB |
Output is correct |
62 |
Correct |
203 ms |
15724 KB |
Output is correct |
63 |
Correct |
478 ms |
15056 KB |
Output is correct |
64 |
Correct |
451 ms |
15064 KB |
Output is correct |
65 |
Correct |
461 ms |
15056 KB |
Output is correct |
66 |
Correct |
94 ms |
14060 KB |
Output is correct |
67 |
Correct |
121 ms |
16872 KB |
Output is correct |
68 |
Correct |
121 ms |
16744 KB |
Output is correct |
69 |
Correct |
125 ms |
16748 KB |
Output is correct |
70 |
Correct |
119 ms |
16748 KB |
Output is correct |
71 |
Correct |
114 ms |
16748 KB |
Output is correct |
72 |
Correct |
118 ms |
16744 KB |
Output is correct |
73 |
Correct |
116 ms |
16744 KB |
Output is correct |
74 |
Correct |
114 ms |
16732 KB |
Output is correct |
75 |
Correct |
343 ms |
32460 KB |
Output is correct |
76 |
Correct |
307 ms |
31824 KB |
Output is correct |
77 |
Correct |
322 ms |
30276 KB |
Output is correct |
78 |
Correct |
316 ms |
30024 KB |
Output is correct |
79 |
Correct |
357 ms |
30420 KB |
Output is correct |
80 |
Correct |
346 ms |
30152 KB |
Output is correct |
81 |
Correct |
744 ms |
32392 KB |
Output is correct |
82 |
Correct |
760 ms |
32204 KB |
Output is correct |
83 |
Correct |
838 ms |
32328 KB |
Output is correct |
84 |
Correct |
705 ms |
32720 KB |
Output is correct |
85 |
Correct |
759 ms |
32348 KB |
Output is correct |
86 |
Correct |
783 ms |
32364 KB |
Output is correct |
87 |
Correct |
651 ms |
33512 KB |
Output is correct |
88 |
Correct |
1362 ms |
28360 KB |
Output is correct |
89 |
Correct |
1585 ms |
30788 KB |
Output is correct |
90 |
Correct |
1477 ms |
30784 KB |
Output is correct |
91 |
Correct |
1392 ms |
30916 KB |
Output is correct |
92 |
Correct |
1064 ms |
30784 KB |
Output is correct |
93 |
Correct |
726 ms |
35028 KB |
Output is correct |
94 |
Correct |
438 ms |
30796 KB |
Output is correct |
95 |
Correct |
776 ms |
35156 KB |
Output is correct |
96 |
Correct |
829 ms |
34876 KB |
Output is correct |
97 |
Correct |
525 ms |
30924 KB |
Output is correct |
98 |
Correct |
547 ms |
31780 KB |
Output is correct |
99 |
Correct |
792 ms |
35280 KB |
Output is correct |
100 |
Correct |
633 ms |
35028 KB |
Output is correct |
101 |
Correct |
565 ms |
30800 KB |
Output is correct |
102 |
Correct |
731 ms |
34772 KB |
Output is correct |
103 |
Correct |
530 ms |
31052 KB |
Output is correct |
104 |
Correct |
760 ms |
34900 KB |
Output is correct |
105 |
Correct |
283 ms |
28244 KB |
Output is correct |
106 |
Correct |
387 ms |
33872 KB |
Output is correct |
107 |
Correct |
387 ms |
34000 KB |
Output is correct |
108 |
Correct |
402 ms |
34004 KB |
Output is correct |
109 |
Correct |
396 ms |
34004 KB |
Output is correct |
110 |
Correct |
390 ms |
33996 KB |
Output is correct |
111 |
Correct |
386 ms |
33996 KB |
Output is correct |
112 |
Correct |
393 ms |
33876 KB |
Output is correct |
113 |
Correct |
443 ms |
34000 KB |
Output is correct |
114 |
Correct |
379 ms |
33876 KB |
Output is correct |
115 |
Correct |
391 ms |
34124 KB |
Output is correct |
116 |
Correct |
381 ms |
35156 KB |
Output is correct |