#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int N,X[300300],Y[300300],R[300300];
int C,XP[600600],p[300300][2];
pair<int, int> CR[300300];
int pick[300300];
const int Z = 1 << 21;
vector<pair<int, int> > grp[Z*2];
vector<int> par[Z*2];
bool intersect(int i, int j)
{
return (long long)(X[i] - X[j]) * (X[i] - X[j]) + (long long)(Y[i] - Y[j]) * (Y[i] - Y[j])
<= + (long long)(R[i] + R[j]) * (R[i] + R[j]);
}
int find(vector<int> &par, int x)
{
if (par[x] != x) par[x] = find(par,par[x]);
return par[x];
}
void go(int x, int i)
{
auto &G = grp[x];
auto &P = par[x];
int j = lower_bound(G.begin(),G.end(),make_pair(Y[i]-R[i],0)) - G.begin();
int u = Y[i] + R[i];
while (j < G.size() && G[j].first <= u){
if (find(P,j) != j){
j = find(P,j);
continue;
}
if (pick[G[j].second] == 0 && intersect(i,G[j].second)) pick[G[j].second] = i;
if (pick[G[j].second]) P[j] = j + 1;
else j++;
}
}
int main()
{
scanf ("%d",&N);
for (int i=1;i<=N;i++){
scanf ("%d %d %d",&X[i],&Y[i],&R[i]);
XP[C++] = X[i] - R[i];
XP[C++] = X[i] + R[i];
CR[i-1] = {R[i],-i};
}
sort(XP,XP+C);
C = unique(XP,XP+C) - XP;
for (int i=1;i<=N;i++){
p[i][0] = lower_bound(XP,XP+C,X[i]-R[i]) - XP + Z;
p[i][1] = lower_bound(XP,XP+C,X[i]+R[i]) - XP + Z;
grp[p[i][0]].push_back({Y[i]-R[i],i});
grp[p[i][0]].push_back({Y[i]+R[i],i});
grp[p[i][1]].push_back({Y[i]-R[i],i});
grp[p[i][1]].push_back({Y[i]+R[i],i});
}
for (int i=Z;i<Z*2;i++) if (!grp[i].empty()) sort(grp[i].begin(),grp[i].end());
for (int i=Z-1;i>=1;i--){
auto &u = grp[i*2], &v = grp[i*2+1], &w = grp[i];
w.resize(u.size()+v.size());
int p = 0, q = 0, r = 0;
while (p < u.size() || q < v.size()){
w[r++] = (q == v.size() || (p < u.size() && u[p] < v[q])) ? u[p++] : v[q++];
}
}
for (int i=1;i<Z*2;i++){
par[i].resize(grp[i].size()+1);
for (int j=0;j<par[i].size();j++) par[i][j] = j;
}
sort(CR,CR+N);
reverse(CR,CR+N);
for (int j=0;j<N;j++) if (pick[-CR[j].second] == 0){
int i = -CR[j].second;
int x = p[i][0];
int y = p[i][1];
while (x < y){
if (x & 1) go(x++,i);
if (~y & 1) go(y--,i);
x /= 2; y /= 2;
} if (x == y) go(x,i);
}
for (int i=1;i<=N;i++) printf ("%d%c",pick[i],i<N?' ':'\n');
return 0;
}
Compilation message
circle_selection.cpp: In function 'void go(int, int)':
circle_selection.cpp:33:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (j < G.size() && G[j].first <= u){
~~^~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:70:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (p < u.size() || q < v.size()){
~~^~~~~~~~~~
circle_selection.cpp:70:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (p < u.size() || q < v.size()){
~~^~~~~~~~~~
circle_selection.cpp:71:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
w[r++] = (q == v.size() || (p < u.size() && u[p] < v[q])) ? u[p++] : v[q++];
~~^~~~~~~~~~~
circle_selection.cpp:71:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
w[r++] = (q == v.size() || (p < u.size() && u[p] < v[q])) ? u[p++] : v[q++];
~~^~~~~~~~~~
circle_selection.cpp:76:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0;j<par[i].size();j++) par[i][j] = j;
~^~~~~~~~~~~~~~
circle_selection.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d",&N);
~~~~~~^~~~~~~~~
circle_selection.cpp:48:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d %d",&X[i],&Y[i],&R[i]);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
500 ms |
328708 KB |
Output is correct |
2 |
Correct |
487 ms |
328808 KB |
Output is correct |
3 |
Correct |
531 ms |
328860 KB |
Output is correct |
4 |
Correct |
578 ms |
328860 KB |
Output is correct |
5 |
Correct |
470 ms |
328860 KB |
Output is correct |
6 |
Correct |
527 ms |
329080 KB |
Output is correct |
7 |
Correct |
529 ms |
329080 KB |
Output is correct |
8 |
Correct |
548 ms |
329232 KB |
Output is correct |
9 |
Correct |
548 ms |
329232 KB |
Output is correct |
10 |
Correct |
558 ms |
329232 KB |
Output is correct |
11 |
Correct |
501 ms |
329232 KB |
Output is correct |
12 |
Correct |
547 ms |
329232 KB |
Output is correct |
13 |
Correct |
508 ms |
329232 KB |
Output is correct |
14 |
Correct |
502 ms |
329232 KB |
Output is correct |
15 |
Correct |
557 ms |
329232 KB |
Output is correct |
16 |
Correct |
540 ms |
330016 KB |
Output is correct |
17 |
Correct |
509 ms |
330088 KB |
Output is correct |
18 |
Correct |
550 ms |
330184 KB |
Output is correct |
19 |
Correct |
556 ms |
334412 KB |
Output is correct |
20 |
Correct |
531 ms |
334508 KB |
Output is correct |
21 |
Correct |
516 ms |
334508 KB |
Output is correct |
22 |
Correct |
506 ms |
334508 KB |
Output is correct |
23 |
Correct |
510 ms |
334600 KB |
Output is correct |
24 |
Correct |
501 ms |
334600 KB |
Output is correct |
25 |
Correct |
505 ms |
334600 KB |
Output is correct |
26 |
Correct |
503 ms |
334600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1927 ms |
658228 KB |
Output is correct |
2 |
Correct |
1957 ms |
658228 KB |
Output is correct |
3 |
Correct |
1889 ms |
658228 KB |
Output is correct |
4 |
Correct |
1778 ms |
658380 KB |
Output is correct |
5 |
Correct |
1728 ms |
658380 KB |
Output is correct |
6 |
Correct |
2001 ms |
658380 KB |
Output is correct |
7 |
Correct |
1897 ms |
658380 KB |
Output is correct |
8 |
Correct |
1673 ms |
658380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
459 ms |
658380 KB |
Output is correct |
2 |
Correct |
958 ms |
658380 KB |
Output is correct |
3 |
Correct |
2107 ms |
658380 KB |
Output is correct |
4 |
Correct |
2189 ms |
658380 KB |
Output is correct |
5 |
Correct |
2500 ms |
658380 KB |
Output is correct |
6 |
Correct |
1209 ms |
658380 KB |
Output is correct |
7 |
Correct |
864 ms |
658380 KB |
Output is correct |
8 |
Correct |
605 ms |
658380 KB |
Output is correct |
9 |
Correct |
2069 ms |
658380 KB |
Output is correct |
10 |
Correct |
2279 ms |
658380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1844 ms |
658380 KB |
Output is correct |
2 |
Correct |
1575 ms |
658380 KB |
Output is correct |
3 |
Correct |
2039 ms |
658380 KB |
Output is correct |
4 |
Correct |
1881 ms |
658380 KB |
Output is correct |
5 |
Correct |
2019 ms |
658380 KB |
Output is correct |
6 |
Correct |
2132 ms |
658380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
500 ms |
328708 KB |
Output is correct |
2 |
Correct |
487 ms |
328808 KB |
Output is correct |
3 |
Correct |
531 ms |
328860 KB |
Output is correct |
4 |
Correct |
578 ms |
328860 KB |
Output is correct |
5 |
Correct |
470 ms |
328860 KB |
Output is correct |
6 |
Correct |
527 ms |
329080 KB |
Output is correct |
7 |
Correct |
529 ms |
329080 KB |
Output is correct |
8 |
Correct |
548 ms |
329232 KB |
Output is correct |
9 |
Correct |
548 ms |
329232 KB |
Output is correct |
10 |
Correct |
558 ms |
329232 KB |
Output is correct |
11 |
Correct |
501 ms |
329232 KB |
Output is correct |
12 |
Correct |
547 ms |
329232 KB |
Output is correct |
13 |
Correct |
508 ms |
329232 KB |
Output is correct |
14 |
Correct |
502 ms |
329232 KB |
Output is correct |
15 |
Correct |
557 ms |
329232 KB |
Output is correct |
16 |
Correct |
540 ms |
330016 KB |
Output is correct |
17 |
Correct |
509 ms |
330088 KB |
Output is correct |
18 |
Correct |
550 ms |
330184 KB |
Output is correct |
19 |
Correct |
556 ms |
334412 KB |
Output is correct |
20 |
Correct |
531 ms |
334508 KB |
Output is correct |
21 |
Correct |
516 ms |
334508 KB |
Output is correct |
22 |
Correct |
506 ms |
334508 KB |
Output is correct |
23 |
Correct |
510 ms |
334600 KB |
Output is correct |
24 |
Correct |
501 ms |
334600 KB |
Output is correct |
25 |
Correct |
505 ms |
334600 KB |
Output is correct |
26 |
Correct |
503 ms |
334600 KB |
Output is correct |
27 |
Correct |
629 ms |
658380 KB |
Output is correct |
28 |
Correct |
591 ms |
658380 KB |
Output is correct |
29 |
Correct |
616 ms |
658380 KB |
Output is correct |
30 |
Correct |
588 ms |
658380 KB |
Output is correct |
31 |
Correct |
608 ms |
658380 KB |
Output is correct |
32 |
Correct |
593 ms |
658380 KB |
Output is correct |
33 |
Correct |
964 ms |
658380 KB |
Output is correct |
34 |
Correct |
864 ms |
658380 KB |
Output is correct |
35 |
Correct |
935 ms |
658380 KB |
Output is correct |
36 |
Correct |
905 ms |
658380 KB |
Output is correct |
37 |
Correct |
888 ms |
658380 KB |
Output is correct |
38 |
Correct |
1012 ms |
658380 KB |
Output is correct |
39 |
Correct |
760 ms |
658380 KB |
Output is correct |
40 |
Correct |
855 ms |
658380 KB |
Output is correct |
41 |
Correct |
770 ms |
658380 KB |
Output is correct |
42 |
Correct |
751 ms |
658380 KB |
Output is correct |
43 |
Correct |
866 ms |
658380 KB |
Output is correct |
44 |
Correct |
880 ms |
658380 KB |
Output is correct |
45 |
Correct |
838 ms |
658380 KB |
Output is correct |
46 |
Correct |
853 ms |
658380 KB |
Output is correct |
47 |
Correct |
860 ms |
658380 KB |
Output is correct |
48 |
Correct |
848 ms |
658380 KB |
Output is correct |
49 |
Correct |
829 ms |
658380 KB |
Output is correct |
50 |
Correct |
869 ms |
658380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
500 ms |
328708 KB |
Output is correct |
2 |
Correct |
487 ms |
328808 KB |
Output is correct |
3 |
Correct |
531 ms |
328860 KB |
Output is correct |
4 |
Correct |
578 ms |
328860 KB |
Output is correct |
5 |
Correct |
470 ms |
328860 KB |
Output is correct |
6 |
Correct |
527 ms |
329080 KB |
Output is correct |
7 |
Correct |
529 ms |
329080 KB |
Output is correct |
8 |
Correct |
548 ms |
329232 KB |
Output is correct |
9 |
Correct |
548 ms |
329232 KB |
Output is correct |
10 |
Correct |
558 ms |
329232 KB |
Output is correct |
11 |
Correct |
501 ms |
329232 KB |
Output is correct |
12 |
Correct |
547 ms |
329232 KB |
Output is correct |
13 |
Correct |
508 ms |
329232 KB |
Output is correct |
14 |
Correct |
502 ms |
329232 KB |
Output is correct |
15 |
Correct |
557 ms |
329232 KB |
Output is correct |
16 |
Correct |
540 ms |
330016 KB |
Output is correct |
17 |
Correct |
509 ms |
330088 KB |
Output is correct |
18 |
Correct |
550 ms |
330184 KB |
Output is correct |
19 |
Correct |
556 ms |
334412 KB |
Output is correct |
20 |
Correct |
531 ms |
334508 KB |
Output is correct |
21 |
Correct |
516 ms |
334508 KB |
Output is correct |
22 |
Correct |
506 ms |
334508 KB |
Output is correct |
23 |
Correct |
510 ms |
334600 KB |
Output is correct |
24 |
Correct |
501 ms |
334600 KB |
Output is correct |
25 |
Correct |
505 ms |
334600 KB |
Output is correct |
26 |
Correct |
503 ms |
334600 KB |
Output is correct |
27 |
Correct |
1927 ms |
658228 KB |
Output is correct |
28 |
Correct |
1957 ms |
658228 KB |
Output is correct |
29 |
Correct |
1889 ms |
658228 KB |
Output is correct |
30 |
Correct |
1778 ms |
658380 KB |
Output is correct |
31 |
Correct |
1728 ms |
658380 KB |
Output is correct |
32 |
Correct |
2001 ms |
658380 KB |
Output is correct |
33 |
Correct |
1897 ms |
658380 KB |
Output is correct |
34 |
Correct |
1673 ms |
658380 KB |
Output is correct |
35 |
Correct |
459 ms |
658380 KB |
Output is correct |
36 |
Correct |
958 ms |
658380 KB |
Output is correct |
37 |
Correct |
2107 ms |
658380 KB |
Output is correct |
38 |
Correct |
2189 ms |
658380 KB |
Output is correct |
39 |
Correct |
2500 ms |
658380 KB |
Output is correct |
40 |
Correct |
1209 ms |
658380 KB |
Output is correct |
41 |
Correct |
864 ms |
658380 KB |
Output is correct |
42 |
Correct |
605 ms |
658380 KB |
Output is correct |
43 |
Correct |
2069 ms |
658380 KB |
Output is correct |
44 |
Correct |
2279 ms |
658380 KB |
Output is correct |
45 |
Correct |
1844 ms |
658380 KB |
Output is correct |
46 |
Correct |
1575 ms |
658380 KB |
Output is correct |
47 |
Correct |
2039 ms |
658380 KB |
Output is correct |
48 |
Correct |
1881 ms |
658380 KB |
Output is correct |
49 |
Correct |
2019 ms |
658380 KB |
Output is correct |
50 |
Correct |
2132 ms |
658380 KB |
Output is correct |
51 |
Correct |
629 ms |
658380 KB |
Output is correct |
52 |
Correct |
591 ms |
658380 KB |
Output is correct |
53 |
Correct |
616 ms |
658380 KB |
Output is correct |
54 |
Correct |
588 ms |
658380 KB |
Output is correct |
55 |
Correct |
608 ms |
658380 KB |
Output is correct |
56 |
Correct |
593 ms |
658380 KB |
Output is correct |
57 |
Correct |
964 ms |
658380 KB |
Output is correct |
58 |
Correct |
864 ms |
658380 KB |
Output is correct |
59 |
Correct |
935 ms |
658380 KB |
Output is correct |
60 |
Correct |
905 ms |
658380 KB |
Output is correct |
61 |
Correct |
888 ms |
658380 KB |
Output is correct |
62 |
Correct |
1012 ms |
658380 KB |
Output is correct |
63 |
Correct |
760 ms |
658380 KB |
Output is correct |
64 |
Correct |
855 ms |
658380 KB |
Output is correct |
65 |
Correct |
770 ms |
658380 KB |
Output is correct |
66 |
Correct |
751 ms |
658380 KB |
Output is correct |
67 |
Correct |
866 ms |
658380 KB |
Output is correct |
68 |
Correct |
880 ms |
658380 KB |
Output is correct |
69 |
Correct |
838 ms |
658380 KB |
Output is correct |
70 |
Correct |
853 ms |
658380 KB |
Output is correct |
71 |
Correct |
860 ms |
658380 KB |
Output is correct |
72 |
Correct |
848 ms |
658380 KB |
Output is correct |
73 |
Correct |
829 ms |
658380 KB |
Output is correct |
74 |
Correct |
869 ms |
658380 KB |
Output is correct |
75 |
Correct |
2001 ms |
658380 KB |
Output is correct |
76 |
Correct |
2095 ms |
658380 KB |
Output is correct |
77 |
Correct |
2144 ms |
658400 KB |
Output is correct |
78 |
Correct |
1971 ms |
658400 KB |
Output is correct |
79 |
Correct |
1957 ms |
658400 KB |
Output is correct |
80 |
Correct |
2166 ms |
658400 KB |
Output is correct |
81 |
Correct |
2368 ms |
658400 KB |
Output is correct |
82 |
Correct |
2233 ms |
658400 KB |
Output is correct |
83 |
Correct |
2318 ms |
658400 KB |
Output is correct |
84 |
Correct |
2433 ms |
658424 KB |
Output is correct |
85 |
Correct |
2245 ms |
658424 KB |
Output is correct |
86 |
Correct |
2150 ms |
658424 KB |
Output is correct |
87 |
Correct |
2757 ms |
658424 KB |
Output is correct |
88 |
Correct |
1518 ms |
658424 KB |
Output is correct |
89 |
Correct |
1542 ms |
658424 KB |
Output is correct |
90 |
Correct |
1615 ms |
658424 KB |
Output is correct |
91 |
Correct |
1561 ms |
658424 KB |
Output is correct |
92 |
Correct |
1640 ms |
658424 KB |
Output is correct |
93 |
Correct |
1762 ms |
658424 KB |
Output is correct |
94 |
Correct |
1991 ms |
658424 KB |
Output is correct |
95 |
Correct |
1918 ms |
658424 KB |
Output is correct |
96 |
Correct |
2048 ms |
658424 KB |
Output is correct |
97 |
Correct |
2079 ms |
658424 KB |
Output is correct |
98 |
Correct |
1882 ms |
658424 KB |
Output is correct |
99 |
Correct |
1858 ms |
658424 KB |
Output is correct |
100 |
Correct |
1694 ms |
658424 KB |
Output is correct |
101 |
Correct |
2112 ms |
658424 KB |
Output is correct |
102 |
Correct |
1985 ms |
658424 KB |
Output is correct |
103 |
Correct |
2167 ms |
658424 KB |
Output is correct |
104 |
Correct |
1994 ms |
658424 KB |
Output is correct |
105 |
Correct |
1511 ms |
658424 KB |
Output is correct |
106 |
Correct |
2025 ms |
658424 KB |
Output is correct |
107 |
Correct |
1957 ms |
658424 KB |
Output is correct |
108 |
Correct |
1824 ms |
658424 KB |
Output is correct |
109 |
Correct |
1737 ms |
658424 KB |
Output is correct |
110 |
Correct |
1752 ms |
658424 KB |
Output is correct |
111 |
Correct |
1646 ms |
658424 KB |
Output is correct |
112 |
Correct |
1710 ms |
658424 KB |
Output is correct |
113 |
Correct |
1630 ms |
658424 KB |
Output is correct |
114 |
Correct |
1634 ms |
658424 KB |
Output is correct |
115 |
Correct |
1850 ms |
658424 KB |
Output is correct |
116 |
Correct |
1744 ms |
658428 KB |
Output is correct |