#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 300000;
int xc[1+MAX_N], yc[1+MAX_N], rc[1+MAX_N];
int poz[1+MAX_N], rez[1+MAX_N];
double ld[1+MAX_N], rd[1+MAX_N];
set<pair<double, int>> sl, sr;
bool cmp(int a, int b) {
return rc[a] > rc[b] || (rc[a] == rc[b] && a < b);
}
double dist(int xa, int ya, int xb, int yb) {
return sqrt((long long)(xa - xb) * (xa - xb) +
(long long)(ya - yb) * (ya - yb));
}
int main() {
#ifdef HOME
FILE *fin = fopen("input.in", "r");
FILE *fout = fopen("output.out", "w");
#else
FILE *fin = stdin;
FILE *fout = stdout;
#endif
int n, ox, oy;
srand(time(NULL));
ox = rand() % 2000000001 - 1000000000;
oy = rand() % 2000000001 - 1000000000;
fscanf(fin, "%d", &n);
for(int i = 1; i <= n; ++i) {
fscanf(fin, "%d%d%d", &xc[i], &yc[i], &rc[i]);
double d = dist(ox, oy, xc[i], yc[i]);
ld[i] = d - rc[i];
rd[i] = d + rc[i];
sl.insert(make_pair(ld[i], i));
sr.insert(make_pair(rd[i], i));
poz[i - 1] = i;
}
sort(poz, poz + n, cmp);
for(int i = 0; i < n; ++i) {
int x = poz[i];
if(rez[x] == 0) {
set<pair<double, int> >::iterator it;
it = sl.lower_bound(make_pair(ld[x], -1));
while(it != sl.end() && it->first <= rd[x]) {
int todel = it->second;
if(rc[x] + rc[todel] >= dist(xc[x], yc[x], xc[todel], yc[todel])) {
rez[todel] = x;
sr.erase(make_pair(rd[todel], todel));
it = sl.erase(it);
} else
it++;
}
it = sr.lower_bound(make_pair(ld[x], -1));
while(it != sr.end() && it->first <= rd[x]) {
int todel = it->second;
if(rc[x] + rc[todel] >= dist(xc[x], yc[x], xc[todel], yc[todel])) {
rez[todel] = x;
sl.erase(make_pair(ld[todel], todel));
it = sr.erase(it);
} else
it++;
}
}
}
for(int i = 1; i <= n; ++i)
fprintf(fout, "%d ", rez[i]);
#ifdef HOME
fclose(fin);
fclose(fout);
#endif
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:36:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf(fin, "%d", &n);
~~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:38:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf(fin, "%d%d%d", &xc[i], &yc[i], &rc[i]);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
524 KB |
Output is correct |
5 |
Correct |
2 ms |
540 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
624 KB |
Output is correct |
11 |
Correct |
2 ms |
628 KB |
Output is correct |
12 |
Correct |
2 ms |
632 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
764 KB |
Output is correct |
15 |
Correct |
2 ms |
764 KB |
Output is correct |
16 |
Correct |
3 ms |
912 KB |
Output is correct |
17 |
Correct |
3 ms |
976 KB |
Output is correct |
18 |
Correct |
3 ms |
976 KB |
Output is correct |
19 |
Correct |
9 ms |
1884 KB |
Output is correct |
20 |
Correct |
8 ms |
1928 KB |
Output is correct |
21 |
Correct |
9 ms |
2204 KB |
Output is correct |
22 |
Correct |
10 ms |
2248 KB |
Output is correct |
23 |
Correct |
9 ms |
2380 KB |
Output is correct |
24 |
Correct |
20 ms |
2640 KB |
Output is correct |
25 |
Correct |
10 ms |
2684 KB |
Output is correct |
26 |
Correct |
10 ms |
2812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1420 ms |
52192 KB |
Output is correct |
2 |
Correct |
1398 ms |
52192 KB |
Output is correct |
3 |
Correct |
1437 ms |
58672 KB |
Output is correct |
4 |
Correct |
1417 ms |
65696 KB |
Output is correct |
5 |
Correct |
1169 ms |
70008 KB |
Output is correct |
6 |
Correct |
1076 ms |
74800 KB |
Output is correct |
7 |
Correct |
984 ms |
79676 KB |
Output is correct |
8 |
Correct |
1149 ms |
84292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
84292 KB |
Output is correct |
2 |
Correct |
508 ms |
84292 KB |
Output is correct |
3 |
Execution timed out |
3058 ms |
84292 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1657 ms |
84456 KB |
Output is correct |
2 |
Correct |
1324 ms |
84456 KB |
Output is correct |
3 |
Execution timed out |
3024 ms |
84456 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
524 KB |
Output is correct |
5 |
Correct |
2 ms |
540 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
624 KB |
Output is correct |
11 |
Correct |
2 ms |
628 KB |
Output is correct |
12 |
Correct |
2 ms |
632 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
764 KB |
Output is correct |
15 |
Correct |
2 ms |
764 KB |
Output is correct |
16 |
Correct |
3 ms |
912 KB |
Output is correct |
17 |
Correct |
3 ms |
976 KB |
Output is correct |
18 |
Correct |
3 ms |
976 KB |
Output is correct |
19 |
Correct |
9 ms |
1884 KB |
Output is correct |
20 |
Correct |
8 ms |
1928 KB |
Output is correct |
21 |
Correct |
9 ms |
2204 KB |
Output is correct |
22 |
Correct |
10 ms |
2248 KB |
Output is correct |
23 |
Correct |
9 ms |
2380 KB |
Output is correct |
24 |
Correct |
20 ms |
2640 KB |
Output is correct |
25 |
Correct |
10 ms |
2684 KB |
Output is correct |
26 |
Correct |
10 ms |
2812 KB |
Output is correct |
27 |
Correct |
18 ms |
84456 KB |
Output is correct |
28 |
Correct |
18 ms |
84456 KB |
Output is correct |
29 |
Correct |
19 ms |
84456 KB |
Output is correct |
30 |
Correct |
24 ms |
84456 KB |
Output is correct |
31 |
Correct |
21 ms |
84456 KB |
Output is correct |
32 |
Correct |
22 ms |
84456 KB |
Output is correct |
33 |
Correct |
337 ms |
84456 KB |
Output is correct |
34 |
Correct |
341 ms |
84456 KB |
Output is correct |
35 |
Correct |
340 ms |
84456 KB |
Output is correct |
36 |
Correct |
467 ms |
84456 KB |
Output is correct |
37 |
Correct |
427 ms |
84456 KB |
Output is correct |
38 |
Correct |
498 ms |
84456 KB |
Output is correct |
39 |
Correct |
2346 ms |
84456 KB |
Output is correct |
40 |
Correct |
2134 ms |
84456 KB |
Output is correct |
41 |
Correct |
2163 ms |
84456 KB |
Output is correct |
42 |
Correct |
1387 ms |
84456 KB |
Output is correct |
43 |
Correct |
254 ms |
84456 KB |
Output is correct |
44 |
Correct |
289 ms |
84456 KB |
Output is correct |
45 |
Correct |
264 ms |
84456 KB |
Output is correct |
46 |
Correct |
247 ms |
84940 KB |
Output is correct |
47 |
Correct |
274 ms |
87584 KB |
Output is correct |
48 |
Correct |
280 ms |
90076 KB |
Output is correct |
49 |
Correct |
268 ms |
92744 KB |
Output is correct |
50 |
Correct |
290 ms |
95372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
524 KB |
Output is correct |
5 |
Correct |
2 ms |
540 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
624 KB |
Output is correct |
11 |
Correct |
2 ms |
628 KB |
Output is correct |
12 |
Correct |
2 ms |
632 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
764 KB |
Output is correct |
15 |
Correct |
2 ms |
764 KB |
Output is correct |
16 |
Correct |
3 ms |
912 KB |
Output is correct |
17 |
Correct |
3 ms |
976 KB |
Output is correct |
18 |
Correct |
3 ms |
976 KB |
Output is correct |
19 |
Correct |
9 ms |
1884 KB |
Output is correct |
20 |
Correct |
8 ms |
1928 KB |
Output is correct |
21 |
Correct |
9 ms |
2204 KB |
Output is correct |
22 |
Correct |
10 ms |
2248 KB |
Output is correct |
23 |
Correct |
9 ms |
2380 KB |
Output is correct |
24 |
Correct |
20 ms |
2640 KB |
Output is correct |
25 |
Correct |
10 ms |
2684 KB |
Output is correct |
26 |
Correct |
10 ms |
2812 KB |
Output is correct |
27 |
Correct |
1420 ms |
52192 KB |
Output is correct |
28 |
Correct |
1398 ms |
52192 KB |
Output is correct |
29 |
Correct |
1437 ms |
58672 KB |
Output is correct |
30 |
Correct |
1417 ms |
65696 KB |
Output is correct |
31 |
Correct |
1169 ms |
70008 KB |
Output is correct |
32 |
Correct |
1076 ms |
74800 KB |
Output is correct |
33 |
Correct |
984 ms |
79676 KB |
Output is correct |
34 |
Correct |
1149 ms |
84292 KB |
Output is correct |
35 |
Correct |
2 ms |
84292 KB |
Output is correct |
36 |
Correct |
508 ms |
84292 KB |
Output is correct |
37 |
Execution timed out |
3058 ms |
84292 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |