// Null
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#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 >= 5*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 |
6 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
4 ms |
7424 KB |
Output is correct |
5 |
Correct |
5 ms |
7424 KB |
Output is correct |
6 |
Correct |
6 ms |
7424 KB |
Output is correct |
7 |
Correct |
4 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
5 ms |
7424 KB |
Output is correct |
10 |
Correct |
6 ms |
7424 KB |
Output is correct |
11 |
Correct |
4 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 |
4 ms |
7424 KB |
Output is correct |
15 |
Correct |
5 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7424 KB |
Output is correct |
19 |
Correct |
10 ms |
7680 KB |
Output is correct |
20 |
Correct |
9 ms |
7680 KB |
Output is correct |
21 |
Correct |
10 ms |
7680 KB |
Output is correct |
22 |
Correct |
11 ms |
7680 KB |
Output is correct |
23 |
Correct |
11 ms |
7680 KB |
Output is correct |
24 |
Correct |
10 ms |
7680 KB |
Output is correct |
25 |
Correct |
10 ms |
7808 KB |
Output is correct |
26 |
Correct |
11 ms |
7680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
277 ms |
21444 KB |
Output is correct |
2 |
Correct |
273 ms |
22740 KB |
Output is correct |
3 |
Correct |
262 ms |
23644 KB |
Output is correct |
4 |
Correct |
277 ms |
21476 KB |
Output is correct |
5 |
Correct |
303 ms |
22776 KB |
Output is correct |
6 |
Correct |
400 ms |
24268 KB |
Output is correct |
7 |
Correct |
309 ms |
22992 KB |
Output is correct |
8 |
Correct |
325 ms |
23120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
152 ms |
12780 KB |
Output is correct |
3 |
Correct |
518 ms |
23288 KB |
Output is correct |
4 |
Correct |
557 ms |
23260 KB |
Output is correct |
5 |
Correct |
486 ms |
22900 KB |
Output is correct |
6 |
Correct |
213 ms |
15200 KB |
Output is correct |
7 |
Correct |
112 ms |
11628 KB |
Output is correct |
8 |
Correct |
25 ms |
8448 KB |
Output is correct |
9 |
Correct |
521 ms |
23764 KB |
Output is correct |
10 |
Correct |
463 ms |
23156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
506 ms |
23628 KB |
Output is correct |
2 |
Correct |
561 ms |
28376 KB |
Output is correct |
3 |
Correct |
319 ms |
21716 KB |
Output is correct |
4 |
Correct |
557 ms |
27728 KB |
Output is correct |
5 |
Correct |
517 ms |
27852 KB |
Output is correct |
6 |
Correct |
306 ms |
20820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
6 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
4 ms |
7424 KB |
Output is correct |
5 |
Correct |
5 ms |
7424 KB |
Output is correct |
6 |
Correct |
6 ms |
7424 KB |
Output is correct |
7 |
Correct |
4 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
5 ms |
7424 KB |
Output is correct |
10 |
Correct |
6 ms |
7424 KB |
Output is correct |
11 |
Correct |
4 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 |
4 ms |
7424 KB |
Output is correct |
15 |
Correct |
5 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7424 KB |
Output is correct |
19 |
Correct |
10 ms |
7680 KB |
Output is correct |
20 |
Correct |
9 ms |
7680 KB |
Output is correct |
21 |
Correct |
10 ms |
7680 KB |
Output is correct |
22 |
Correct |
11 ms |
7680 KB |
Output is correct |
23 |
Correct |
11 ms |
7680 KB |
Output is correct |
24 |
Correct |
10 ms |
7680 KB |
Output is correct |
25 |
Correct |
10 ms |
7808 KB |
Output is correct |
26 |
Correct |
11 ms |
7680 KB |
Output is correct |
27 |
Correct |
13 ms |
7936 KB |
Output is correct |
28 |
Correct |
13 ms |
7936 KB |
Output is correct |
29 |
Correct |
15 ms |
7936 KB |
Output is correct |
30 |
Correct |
17 ms |
7936 KB |
Output is correct |
31 |
Correct |
17 ms |
7936 KB |
Output is correct |
32 |
Correct |
16 ms |
7936 KB |
Output is correct |
33 |
Correct |
119 ms |
12260 KB |
Output is correct |
34 |
Correct |
117 ms |
12392 KB |
Output is correct |
35 |
Correct |
113 ms |
12524 KB |
Output is correct |
36 |
Correct |
152 ms |
13032 KB |
Output is correct |
37 |
Correct |
160 ms |
12900 KB |
Output is correct |
38 |
Correct |
175 ms |
12652 KB |
Output is correct |
39 |
Correct |
224 ms |
14056 KB |
Output is correct |
40 |
Correct |
224 ms |
14056 KB |
Output is correct |
41 |
Correct |
227 ms |
13288 KB |
Output is correct |
42 |
Correct |
92 ms |
12520 KB |
Output is correct |
43 |
Correct |
132 ms |
14132 KB |
Output is correct |
44 |
Correct |
128 ms |
14184 KB |
Output is correct |
45 |
Correct |
131 ms |
14188 KB |
Output is correct |
46 |
Correct |
133 ms |
14184 KB |
Output is correct |
47 |
Correct |
126 ms |
14188 KB |
Output is correct |
48 |
Correct |
128 ms |
14188 KB |
Output is correct |
49 |
Correct |
124 ms |
14184 KB |
Output is correct |
50 |
Correct |
123 ms |
14188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
6 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
4 ms |
7424 KB |
Output is correct |
5 |
Correct |
5 ms |
7424 KB |
Output is correct |
6 |
Correct |
6 ms |
7424 KB |
Output is correct |
7 |
Correct |
4 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
5 ms |
7424 KB |
Output is correct |
10 |
Correct |
6 ms |
7424 KB |
Output is correct |
11 |
Correct |
4 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 |
4 ms |
7424 KB |
Output is correct |
15 |
Correct |
5 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7424 KB |
Output is correct |
19 |
Correct |
10 ms |
7680 KB |
Output is correct |
20 |
Correct |
9 ms |
7680 KB |
Output is correct |
21 |
Correct |
10 ms |
7680 KB |
Output is correct |
22 |
Correct |
11 ms |
7680 KB |
Output is correct |
23 |
Correct |
11 ms |
7680 KB |
Output is correct |
24 |
Correct |
10 ms |
7680 KB |
Output is correct |
25 |
Correct |
10 ms |
7808 KB |
Output is correct |
26 |
Correct |
11 ms |
7680 KB |
Output is correct |
27 |
Correct |
277 ms |
21444 KB |
Output is correct |
28 |
Correct |
273 ms |
22740 KB |
Output is correct |
29 |
Correct |
262 ms |
23644 KB |
Output is correct |
30 |
Correct |
277 ms |
21476 KB |
Output is correct |
31 |
Correct |
303 ms |
22776 KB |
Output is correct |
32 |
Correct |
400 ms |
24268 KB |
Output is correct |
33 |
Correct |
309 ms |
22992 KB |
Output is correct |
34 |
Correct |
325 ms |
23120 KB |
Output is correct |
35 |
Correct |
5 ms |
7424 KB |
Output is correct |
36 |
Correct |
152 ms |
12780 KB |
Output is correct |
37 |
Correct |
518 ms |
23288 KB |
Output is correct |
38 |
Correct |
557 ms |
23260 KB |
Output is correct |
39 |
Correct |
486 ms |
22900 KB |
Output is correct |
40 |
Correct |
213 ms |
15200 KB |
Output is correct |
41 |
Correct |
112 ms |
11628 KB |
Output is correct |
42 |
Correct |
25 ms |
8448 KB |
Output is correct |
43 |
Correct |
521 ms |
23764 KB |
Output is correct |
44 |
Correct |
463 ms |
23156 KB |
Output is correct |
45 |
Correct |
506 ms |
23628 KB |
Output is correct |
46 |
Correct |
561 ms |
28376 KB |
Output is correct |
47 |
Correct |
319 ms |
21716 KB |
Output is correct |
48 |
Correct |
557 ms |
27728 KB |
Output is correct |
49 |
Correct |
517 ms |
27852 KB |
Output is correct |
50 |
Correct |
306 ms |
20820 KB |
Output is correct |
51 |
Correct |
13 ms |
7936 KB |
Output is correct |
52 |
Correct |
13 ms |
7936 KB |
Output is correct |
53 |
Correct |
15 ms |
7936 KB |
Output is correct |
54 |
Correct |
17 ms |
7936 KB |
Output is correct |
55 |
Correct |
17 ms |
7936 KB |
Output is correct |
56 |
Correct |
16 ms |
7936 KB |
Output is correct |
57 |
Correct |
119 ms |
12260 KB |
Output is correct |
58 |
Correct |
117 ms |
12392 KB |
Output is correct |
59 |
Correct |
113 ms |
12524 KB |
Output is correct |
60 |
Correct |
152 ms |
13032 KB |
Output is correct |
61 |
Correct |
160 ms |
12900 KB |
Output is correct |
62 |
Correct |
175 ms |
12652 KB |
Output is correct |
63 |
Correct |
224 ms |
14056 KB |
Output is correct |
64 |
Correct |
224 ms |
14056 KB |
Output is correct |
65 |
Correct |
227 ms |
13288 KB |
Output is correct |
66 |
Correct |
92 ms |
12520 KB |
Output is correct |
67 |
Correct |
132 ms |
14132 KB |
Output is correct |
68 |
Correct |
128 ms |
14184 KB |
Output is correct |
69 |
Correct |
131 ms |
14188 KB |
Output is correct |
70 |
Correct |
133 ms |
14184 KB |
Output is correct |
71 |
Correct |
126 ms |
14188 KB |
Output is correct |
72 |
Correct |
128 ms |
14188 KB |
Output is correct |
73 |
Correct |
124 ms |
14184 KB |
Output is correct |
74 |
Correct |
123 ms |
14188 KB |
Output is correct |
75 |
Correct |
340 ms |
23272 KB |
Output is correct |
76 |
Correct |
333 ms |
22988 KB |
Output is correct |
77 |
Correct |
329 ms |
21508 KB |
Output is correct |
78 |
Correct |
368 ms |
21128 KB |
Output is correct |
79 |
Correct |
354 ms |
21588 KB |
Output is correct |
80 |
Correct |
367 ms |
21060 KB |
Output is correct |
81 |
Correct |
553 ms |
23252 KB |
Output is correct |
82 |
Correct |
551 ms |
23244 KB |
Output is correct |
83 |
Correct |
552 ms |
23196 KB |
Output is correct |
84 |
Correct |
569 ms |
23124 KB |
Output is correct |
85 |
Correct |
574 ms |
23244 KB |
Output is correct |
86 |
Correct |
590 ms |
23640 KB |
Output is correct |
87 |
Correct |
584 ms |
24112 KB |
Output is correct |
88 |
Correct |
767 ms |
27692 KB |
Output is correct |
89 |
Correct |
739 ms |
27692 KB |
Output is correct |
90 |
Correct |
802 ms |
25260 KB |
Output is correct |
91 |
Correct |
734 ms |
27712 KB |
Output is correct |
92 |
Correct |
868 ms |
27680 KB |
Output is correct |
93 |
Correct |
647 ms |
28460 KB |
Output is correct |
94 |
Correct |
408 ms |
22268 KB |
Output is correct |
95 |
Correct |
560 ms |
28608 KB |
Output is correct |
96 |
Correct |
628 ms |
28240 KB |
Output is correct |
97 |
Correct |
522 ms |
22900 KB |
Output is correct |
98 |
Correct |
535 ms |
24532 KB |
Output is correct |
99 |
Correct |
609 ms |
29004 KB |
Output is correct |
100 |
Correct |
522 ms |
29152 KB |
Output is correct |
101 |
Correct |
510 ms |
24144 KB |
Output is correct |
102 |
Correct |
601 ms |
28592 KB |
Output is correct |
103 |
Correct |
474 ms |
23516 KB |
Output is correct |
104 |
Correct |
563 ms |
28748 KB |
Output is correct |
105 |
Correct |
308 ms |
24000 KB |
Output is correct |
106 |
Correct |
439 ms |
26932 KB |
Output is correct |
107 |
Correct |
470 ms |
27024 KB |
Output is correct |
108 |
Correct |
422 ms |
26960 KB |
Output is correct |
109 |
Correct |
426 ms |
26896 KB |
Output is correct |
110 |
Correct |
442 ms |
26960 KB |
Output is correct |
111 |
Correct |
442 ms |
26848 KB |
Output is correct |
112 |
Correct |
418 ms |
26964 KB |
Output is correct |
113 |
Correct |
436 ms |
27000 KB |
Output is correct |
114 |
Correct |
415 ms |
26832 KB |
Output is correct |
115 |
Correct |
419 ms |
26960 KB |
Output is correct |
116 |
Correct |
412 ms |
28108 KB |
Output is correct |