#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double
template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
os<<"("<<p.first<<", "<<p.second<<")";
return os;
}
template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
os<<"{";
for(int i = 0;i < (int)v.size(); i++){
if(i)os<<", ";
os<<v[i];
}
os<<"}";
return os;
}
#ifdef LOCAL
#define cerr cout
#else
#endif
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = 300005;
int x[N], y[N], r[N];
int where[N]; // compression
vector<pii> points[N];
inline ll sq(int x){return x * (ll) x;}
inline bool intersecting(int i, int j){
return sq(x[i] - x[j]) + sq(y[i] - y[j]) <= sq(r[i] + r[j]);
}
int daddy[N];
int main(){
memset(daddy, -1, sizeof daddy);
int n; sd(n);
for(int i = 0; i < n; i++){
sd(x[i]); sd(y[i]); sd(r[i]);
}
vector<int> perm(n), xsorted(n), ysorted(n);
iota(all(perm), 0);
iota(all(xsorted), 0);
iota(all(ysorted), 0);
stable_sort(all(perm), [](int i, int j){return r[i] > r[j];});
stable_sort(all(xsorted), [](int i, int j){return x[i] < x[j];});
stable_sort(all(ysorted), [](int i, int j){return y[i] < y[j];});
vector<int> compressedX;
function<void(int)> compress = [&](int R){
for(int j = 0; j < sz(compressedX); j++) points[j].clear();
compressedX.clear();
int curr = x[xsorted[0]] / R;
compressedX.push_back(curr);
for(int i = 0; i < n; i++){
int pos = xsorted[i];
if(x[pos] / R == curr){
where[pos] = sz(compressedX) - 1;
} else{
compressedX.push_back(curr = x[pos] / R);
where[pos] = sz(compressedX) - 1;
}
}
for(int pos : ysorted){
points[where[pos]].push_back({y[pos], pos});
}
};
int R = 2000000001;
for(int pos : perm){
if(daddy[pos] != -1) continue;
if(2 * r[pos] < R){
R = r[pos];
compress(R);
}
daddy[pos] = pos;
int p = lower_bound(all(compressedX), x[pos] / R - 2) - compressedX.begin();
int mx = x[pos] / R + 2;
for(;p < sz(compressedX) && compressedX[p] <= mx; p++) if(!points[p].empty()){
int mn = y[pos] + 1e9 < 2 * R ? -1e9 - 10 : y[pos] - 2 * R;
int mx = y[pos] - 1e9 > -2 * R ? 1e9 + 10 : y[pos] + 2 * R;
int q = lower_bound(all(points[p]), make_pair(mn, -1)) - points[p].begin();
while(q < sz(points[p]) && points[p][q].first <= mx){
int t = points[p][q].S;
if(daddy[t] == -1 && intersecting(pos, t)){
daddy[t] = pos;
}
q++;
}
}
}
for(int i = 0; i < n; i++) printf("%d ", daddy[i] + 1);
printf("\n");
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:5:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define sd(x) scanf("%d", &(x))
~~~~~^~~~~~~~~~~~
circle_selection.cpp:67:9: note: in expansion of macro 'sd'
int n; sd(n);
^~
circle_selection.cpp:5:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define sd(x) scanf("%d", &(x))
~~~~~^~~~~~~~~~~~
circle_selection.cpp:69:3: note: in expansion of macro 'sd'
sd(x[i]); sd(y[i]); sd(r[i]);
^~
circle_selection.cpp:5:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define sd(x) scanf("%d", &(x))
~~~~~^~~~~~~~~~~~
circle_selection.cpp:69:13: note: in expansion of macro 'sd'
sd(x[i]); sd(y[i]); sd(r[i]);
^~
circle_selection.cpp:5:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define sd(x) scanf("%d", &(x))
~~~~~^~~~~~~~~~~~
circle_selection.cpp:69:23: note: in expansion of macro 'sd'
sd(x[i]); sd(y[i]); sd(r[i]);
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8572 KB |
Output is correct |
2 |
Correct |
10 ms |
8568 KB |
Output is correct |
3 |
Correct |
9 ms |
8568 KB |
Output is correct |
4 |
Correct |
10 ms |
8568 KB |
Output is correct |
5 |
Correct |
9 ms |
8568 KB |
Output is correct |
6 |
Correct |
10 ms |
8568 KB |
Output is correct |
7 |
Correct |
10 ms |
8444 KB |
Output is correct |
8 |
Correct |
10 ms |
8568 KB |
Output is correct |
9 |
Correct |
10 ms |
8568 KB |
Output is correct |
10 |
Correct |
10 ms |
8568 KB |
Output is correct |
11 |
Correct |
10 ms |
8568 KB |
Output is correct |
12 |
Correct |
10 ms |
8568 KB |
Output is correct |
13 |
Correct |
10 ms |
8568 KB |
Output is correct |
14 |
Correct |
10 ms |
8568 KB |
Output is correct |
15 |
Correct |
11 ms |
8568 KB |
Output is correct |
16 |
Correct |
11 ms |
8696 KB |
Output is correct |
17 |
Correct |
12 ms |
8568 KB |
Output is correct |
18 |
Correct |
11 ms |
8568 KB |
Output is correct |
19 |
Correct |
15 ms |
8952 KB |
Output is correct |
20 |
Correct |
15 ms |
8952 KB |
Output is correct |
21 |
Correct |
15 ms |
9080 KB |
Output is correct |
22 |
Correct |
18 ms |
9208 KB |
Output is correct |
23 |
Correct |
18 ms |
9208 KB |
Output is correct |
24 |
Correct |
17 ms |
9080 KB |
Output is correct |
25 |
Correct |
17 ms |
9080 KB |
Output is correct |
26 |
Correct |
17 ms |
9080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
301 ms |
24872 KB |
Output is correct |
2 |
Correct |
297 ms |
24364 KB |
Output is correct |
3 |
Correct |
286 ms |
22828 KB |
Output is correct |
4 |
Correct |
292 ms |
24232 KB |
Output is correct |
5 |
Correct |
380 ms |
31920 KB |
Output is correct |
6 |
Correct |
565 ms |
30376 KB |
Output is correct |
7 |
Correct |
501 ms |
35244 KB |
Output is correct |
8 |
Correct |
522 ms |
32940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8568 KB |
Output is correct |
2 |
Correct |
302 ms |
17588 KB |
Output is correct |
3 |
Correct |
1338 ms |
35552 KB |
Output is correct |
4 |
Correct |
1345 ms |
35368 KB |
Output is correct |
5 |
Correct |
1234 ms |
38948 KB |
Output is correct |
6 |
Correct |
327 ms |
22464 KB |
Output is correct |
7 |
Correct |
199 ms |
15580 KB |
Output is correct |
8 |
Correct |
34 ms |
9720 KB |
Output is correct |
9 |
Correct |
1154 ms |
38664 KB |
Output is correct |
10 |
Correct |
633 ms |
34328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
522 ms |
23820 KB |
Output is correct |
2 |
Correct |
454 ms |
29352 KB |
Output is correct |
3 |
Correct |
340 ms |
21672 KB |
Output is correct |
4 |
Correct |
481 ms |
28588 KB |
Output is correct |
5 |
Correct |
462 ms |
28972 KB |
Output is correct |
6 |
Correct |
330 ms |
20908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8572 KB |
Output is correct |
2 |
Correct |
10 ms |
8568 KB |
Output is correct |
3 |
Correct |
9 ms |
8568 KB |
Output is correct |
4 |
Correct |
10 ms |
8568 KB |
Output is correct |
5 |
Correct |
9 ms |
8568 KB |
Output is correct |
6 |
Correct |
10 ms |
8568 KB |
Output is correct |
7 |
Correct |
10 ms |
8444 KB |
Output is correct |
8 |
Correct |
10 ms |
8568 KB |
Output is correct |
9 |
Correct |
10 ms |
8568 KB |
Output is correct |
10 |
Correct |
10 ms |
8568 KB |
Output is correct |
11 |
Correct |
10 ms |
8568 KB |
Output is correct |
12 |
Correct |
10 ms |
8568 KB |
Output is correct |
13 |
Correct |
10 ms |
8568 KB |
Output is correct |
14 |
Correct |
10 ms |
8568 KB |
Output is correct |
15 |
Correct |
11 ms |
8568 KB |
Output is correct |
16 |
Correct |
11 ms |
8696 KB |
Output is correct |
17 |
Correct |
12 ms |
8568 KB |
Output is correct |
18 |
Correct |
11 ms |
8568 KB |
Output is correct |
19 |
Correct |
15 ms |
8952 KB |
Output is correct |
20 |
Correct |
15 ms |
8952 KB |
Output is correct |
21 |
Correct |
15 ms |
9080 KB |
Output is correct |
22 |
Correct |
18 ms |
9208 KB |
Output is correct |
23 |
Correct |
18 ms |
9208 KB |
Output is correct |
24 |
Correct |
17 ms |
9080 KB |
Output is correct |
25 |
Correct |
17 ms |
9080 KB |
Output is correct |
26 |
Correct |
17 ms |
9080 KB |
Output is correct |
27 |
Correct |
22 ms |
9720 KB |
Output is correct |
28 |
Correct |
21 ms |
9336 KB |
Output is correct |
29 |
Correct |
21 ms |
9336 KB |
Output is correct |
30 |
Correct |
28 ms |
9592 KB |
Output is correct |
31 |
Correct |
28 ms |
9592 KB |
Output is correct |
32 |
Correct |
27 ms |
9568 KB |
Output is correct |
33 |
Correct |
122 ms |
16304 KB |
Output is correct |
34 |
Correct |
128 ms |
16464 KB |
Output is correct |
35 |
Correct |
181 ms |
24120 KB |
Output is correct |
36 |
Correct |
256 ms |
18484 KB |
Output is correct |
37 |
Correct |
259 ms |
18744 KB |
Output is correct |
38 |
Correct |
267 ms |
19124 KB |
Output is correct |
39 |
Correct |
215 ms |
27500 KB |
Output is correct |
40 |
Correct |
218 ms |
27888 KB |
Output is correct |
41 |
Correct |
206 ms |
26740 KB |
Output is correct |
42 |
Correct |
100 ms |
14900 KB |
Output is correct |
43 |
Correct |
138 ms |
17944 KB |
Output is correct |
44 |
Correct |
132 ms |
17972 KB |
Output is correct |
45 |
Correct |
130 ms |
17972 KB |
Output is correct |
46 |
Correct |
131 ms |
17876 KB |
Output is correct |
47 |
Correct |
128 ms |
17972 KB |
Output is correct |
48 |
Correct |
133 ms |
17972 KB |
Output is correct |
49 |
Correct |
129 ms |
18016 KB |
Output is correct |
50 |
Correct |
140 ms |
17972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8572 KB |
Output is correct |
2 |
Correct |
10 ms |
8568 KB |
Output is correct |
3 |
Correct |
9 ms |
8568 KB |
Output is correct |
4 |
Correct |
10 ms |
8568 KB |
Output is correct |
5 |
Correct |
9 ms |
8568 KB |
Output is correct |
6 |
Correct |
10 ms |
8568 KB |
Output is correct |
7 |
Correct |
10 ms |
8444 KB |
Output is correct |
8 |
Correct |
10 ms |
8568 KB |
Output is correct |
9 |
Correct |
10 ms |
8568 KB |
Output is correct |
10 |
Correct |
10 ms |
8568 KB |
Output is correct |
11 |
Correct |
10 ms |
8568 KB |
Output is correct |
12 |
Correct |
10 ms |
8568 KB |
Output is correct |
13 |
Correct |
10 ms |
8568 KB |
Output is correct |
14 |
Correct |
10 ms |
8568 KB |
Output is correct |
15 |
Correct |
11 ms |
8568 KB |
Output is correct |
16 |
Correct |
11 ms |
8696 KB |
Output is correct |
17 |
Correct |
12 ms |
8568 KB |
Output is correct |
18 |
Correct |
11 ms |
8568 KB |
Output is correct |
19 |
Correct |
15 ms |
8952 KB |
Output is correct |
20 |
Correct |
15 ms |
8952 KB |
Output is correct |
21 |
Correct |
15 ms |
9080 KB |
Output is correct |
22 |
Correct |
18 ms |
9208 KB |
Output is correct |
23 |
Correct |
18 ms |
9208 KB |
Output is correct |
24 |
Correct |
17 ms |
9080 KB |
Output is correct |
25 |
Correct |
17 ms |
9080 KB |
Output is correct |
26 |
Correct |
17 ms |
9080 KB |
Output is correct |
27 |
Correct |
301 ms |
24872 KB |
Output is correct |
28 |
Correct |
297 ms |
24364 KB |
Output is correct |
29 |
Correct |
286 ms |
22828 KB |
Output is correct |
30 |
Correct |
292 ms |
24232 KB |
Output is correct |
31 |
Correct |
380 ms |
31920 KB |
Output is correct |
32 |
Correct |
565 ms |
30376 KB |
Output is correct |
33 |
Correct |
501 ms |
35244 KB |
Output is correct |
34 |
Correct |
522 ms |
32940 KB |
Output is correct |
35 |
Correct |
9 ms |
8568 KB |
Output is correct |
36 |
Correct |
302 ms |
17588 KB |
Output is correct |
37 |
Correct |
1338 ms |
35552 KB |
Output is correct |
38 |
Correct |
1345 ms |
35368 KB |
Output is correct |
39 |
Correct |
1234 ms |
38948 KB |
Output is correct |
40 |
Correct |
327 ms |
22464 KB |
Output is correct |
41 |
Correct |
199 ms |
15580 KB |
Output is correct |
42 |
Correct |
34 ms |
9720 KB |
Output is correct |
43 |
Correct |
1154 ms |
38664 KB |
Output is correct |
44 |
Correct |
633 ms |
34328 KB |
Output is correct |
45 |
Correct |
522 ms |
23820 KB |
Output is correct |
46 |
Correct |
454 ms |
29352 KB |
Output is correct |
47 |
Correct |
340 ms |
21672 KB |
Output is correct |
48 |
Correct |
481 ms |
28588 KB |
Output is correct |
49 |
Correct |
462 ms |
28972 KB |
Output is correct |
50 |
Correct |
330 ms |
20908 KB |
Output is correct |
51 |
Correct |
22 ms |
9720 KB |
Output is correct |
52 |
Correct |
21 ms |
9336 KB |
Output is correct |
53 |
Correct |
21 ms |
9336 KB |
Output is correct |
54 |
Correct |
28 ms |
9592 KB |
Output is correct |
55 |
Correct |
28 ms |
9592 KB |
Output is correct |
56 |
Correct |
27 ms |
9568 KB |
Output is correct |
57 |
Correct |
122 ms |
16304 KB |
Output is correct |
58 |
Correct |
128 ms |
16464 KB |
Output is correct |
59 |
Correct |
181 ms |
24120 KB |
Output is correct |
60 |
Correct |
256 ms |
18484 KB |
Output is correct |
61 |
Correct |
259 ms |
18744 KB |
Output is correct |
62 |
Correct |
267 ms |
19124 KB |
Output is correct |
63 |
Correct |
215 ms |
27500 KB |
Output is correct |
64 |
Correct |
218 ms |
27888 KB |
Output is correct |
65 |
Correct |
206 ms |
26740 KB |
Output is correct |
66 |
Correct |
100 ms |
14900 KB |
Output is correct |
67 |
Correct |
138 ms |
17944 KB |
Output is correct |
68 |
Correct |
132 ms |
17972 KB |
Output is correct |
69 |
Correct |
130 ms |
17972 KB |
Output is correct |
70 |
Correct |
131 ms |
17876 KB |
Output is correct |
71 |
Correct |
128 ms |
17972 KB |
Output is correct |
72 |
Correct |
133 ms |
17972 KB |
Output is correct |
73 |
Correct |
129 ms |
18016 KB |
Output is correct |
74 |
Correct |
140 ms |
17972 KB |
Output is correct |
75 |
Correct |
542 ms |
51276 KB |
Output is correct |
76 |
Correct |
385 ms |
34220 KB |
Output is correct |
77 |
Correct |
355 ms |
32168 KB |
Output is correct |
78 |
Correct |
373 ms |
32040 KB |
Output is correct |
79 |
Correct |
675 ms |
52264 KB |
Output is correct |
80 |
Correct |
375 ms |
32204 KB |
Output is correct |
81 |
Correct |
1266 ms |
42664 KB |
Output is correct |
82 |
Correct |
1246 ms |
41424 KB |
Output is correct |
83 |
Correct |
1269 ms |
41340 KB |
Output is correct |
84 |
Correct |
1213 ms |
45012 KB |
Output is correct |
85 |
Correct |
1248 ms |
42288 KB |
Output is correct |
86 |
Correct |
1295 ms |
41128 KB |
Output is correct |
87 |
Correct |
1117 ms |
51928 KB |
Output is correct |
88 |
Correct |
749 ms |
61260 KB |
Output is correct |
89 |
Correct |
733 ms |
63764 KB |
Output is correct |
90 |
Correct |
749 ms |
63660 KB |
Output is correct |
91 |
Correct |
743 ms |
63784 KB |
Output is correct |
92 |
Correct |
745 ms |
66212 KB |
Output is correct |
93 |
Correct |
611 ms |
36392 KB |
Output is correct |
94 |
Correct |
460 ms |
34852 KB |
Output is correct |
95 |
Correct |
611 ms |
36444 KB |
Output is correct |
96 |
Correct |
681 ms |
36520 KB |
Output is correct |
97 |
Correct |
523 ms |
32680 KB |
Output is correct |
98 |
Correct |
706 ms |
37928 KB |
Output is correct |
99 |
Correct |
660 ms |
36396 KB |
Output is correct |
100 |
Correct |
489 ms |
36136 KB |
Output is correct |
101 |
Correct |
751 ms |
39804 KB |
Output is correct |
102 |
Correct |
661 ms |
36452 KB |
Output is correct |
103 |
Correct |
565 ms |
38184 KB |
Output is correct |
104 |
Correct |
674 ms |
36144 KB |
Output is correct |
105 |
Correct |
320 ms |
28484 KB |
Output is correct |
106 |
Correct |
428 ms |
34984 KB |
Output is correct |
107 |
Correct |
422 ms |
34860 KB |
Output is correct |
108 |
Correct |
425 ms |
34988 KB |
Output is correct |
109 |
Correct |
425 ms |
34860 KB |
Output is correct |
110 |
Correct |
432 ms |
34984 KB |
Output is correct |
111 |
Correct |
428 ms |
34984 KB |
Output is correct |
112 |
Correct |
424 ms |
34860 KB |
Output is correct |
113 |
Correct |
428 ms |
34856 KB |
Output is correct |
114 |
Correct |
419 ms |
34856 KB |
Output is correct |
115 |
Correct |
424 ms |
34856 KB |
Output is correct |
116 |
Correct |
420 ms |
36392 KB |
Output is correct |