#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N = 3e5 + 5;
struct node{
int p[2],id;
pp mn[2];
node *l, *r;
node(int a[], int i) { l = r = NULL; p[0] = a[0]; p[1] = a[1]; id = i; }
};
int p[N][2],A[N],B[N],tmp[N],R[N],ans[N],r;
node* bld(int l, int r, int k){
if(l > r) return NULL;
int *X = k ? B : A;
int *Y = k ? A : B;
int i,j,jj, m = l+r >> 1;
int mid = p[ X[m] ][k];
for(; m>l && mid == p[ X[m-1] ][k] ; m--);
node *root = new node(p[ X[m] ] , X[m]);
root->mn[0] = mp( p[ A[l] ][0] , A[l] );
root->mn[1] = mp( p[ B[l] ][1] , B[l] );
for(j=l-1,jj=m,i=l;i<=r;i++){
if(p[ Y[i] ][k] < mid)
tmp[++j] = Y[i];
else if(Y[i] != X[m])
tmp[++jj] = Y[i];
}
for(i=l;i<=r;i++) Y[i] = tmp[i];
root -> l = bld(l,m-1,!k);
root -> r = bld(m+1,r,!k);
return root;
}
node* del(node* root, int i, int k){
if(root == NULL) assert(0);
if(root->id == i){
if(root -> r != NULL){
int j = root->r->mn[k].nd;
root->p[0] = p[j][0]; root->p[1] = p[j][1]; root->id = j;
root -> r = del(root->r, j, !k);
}
else if(root -> l != NULL){
int j = root->l->mn[k].nd;
root->p[0] = p[j][0]; root->p[1] = p[j][1]; root->id = j;
root->r = root->l; root->l = NULL;
root->r = del(root->r, j, !k);
}
else return NULL;
}
else{
if(p[i][k] < root->p[k]) root->l = del(root->l, i, !k);
else root->r = del(root->r, i, !k);
}
root->mn[k] = root->l ? root->l->mn[k] : mp( root->p[k] , root->id );
root->mn[!k] = mp(root->p[!k],root->id);
if(root->l != NULL) root->mn[!k] = min(root->mn[!k] , root->l->mn[!k]);
if(root->r != NULL) root->mn[!k] = min(root->mn[!k] , root->r->mn[!k]);
return root;
}
vector < int > era;
void f(node* root, int p[], int k){
if(root == NULL) return;
ll a1 = root->p[0];
ll b1 = root->p[1];
ll a2 = p[0];
ll b2 = p[1];
ll c = R[ root->id ];
if((a1-a2)*(a1-a2) + (b1-b2)*(b1-b2) <= (r+c)*(r+c))
era.pb(root->id);
if(p[k] < root->p[k]){
f(root->l,p,!k);
if(root->p[k] - p[k] <= r+r) f(root->r,p,!k);
}
else{
f(root->r,p,!k);
if(p[k] - root->p[k] <= r+r) f(root->l,p,!k);
}
}
int h;
bool cmp(int i, int j){
return p[i][h] < p[j][h];
}
int n,i,j;
pp T[N];
int main()
{
cin >> n;
for(i=1;i<=n;i++) { scanf("%d%d%d",&p[i][0],&p[i][1],&R[i]); A[i] = B[i] = i; }
h=0; sort(A+1,A+n+1,cmp);
h=1; sort(B+1,B+n+1,cmp);
node *root = bld(1,n,0);
for(i=1;i<=n;i++) T[i] = mp(-R[i] , i);
sort(T+1 , T+n+1);
for(i=1;i<=n;i++){
int id = T[i].nd;
if(ans[id]) continue;
era.clear();
r = R[id];
f(root , p[id], 0);
for(auto j : era){
ans[j] = id;
root = del(root, j, 0);
}
}
for(i=1;i<=n;i++) printf("%d ", ans[i]);
return 0;
}
Compilation message
circle_selection.cpp: In function 'node* bld(int, int, int)':
circle_selection.cpp:27:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int i,j,jj, m = l+r >> 1;
~^~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:103:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1;i<=n;i++) { scanf("%d%d%d",&p[i][0],&p[i][1],&R[i]); A[i] = B[i] = 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 |
408 KB |
Output is correct |
4 |
Correct |
2 ms |
408 KB |
Output is correct |
5 |
Correct |
3 ms |
456 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
3 ms |
544 KB |
Output is correct |
11 |
Correct |
3 ms |
544 KB |
Output is correct |
12 |
Correct |
2 ms |
544 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
3 ms |
748 KB |
Output is correct |
17 |
Correct |
3 ms |
748 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
19 |
Correct |
10 ms |
1132 KB |
Output is correct |
20 |
Correct |
9 ms |
1132 KB |
Output is correct |
21 |
Correct |
9 ms |
1164 KB |
Output is correct |
22 |
Correct |
16 ms |
1164 KB |
Output is correct |
23 |
Correct |
9 ms |
1164 KB |
Output is correct |
24 |
Correct |
9 ms |
1164 KB |
Output is correct |
25 |
Correct |
10 ms |
1164 KB |
Output is correct |
26 |
Correct |
11 ms |
1164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
521 ms |
33364 KB |
Output is correct |
2 |
Correct |
543 ms |
33364 KB |
Output is correct |
3 |
Correct |
571 ms |
33364 KB |
Output is correct |
4 |
Correct |
640 ms |
33364 KB |
Output is correct |
5 |
Correct |
549 ms |
33364 KB |
Output is correct |
6 |
Correct |
715 ms |
33364 KB |
Output is correct |
7 |
Correct |
726 ms |
33364 KB |
Output is correct |
8 |
Correct |
609 ms |
33364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
33364 KB |
Output is correct |
2 |
Correct |
237 ms |
33364 KB |
Output is correct |
3 |
Correct |
859 ms |
33364 KB |
Output is correct |
4 |
Correct |
787 ms |
33364 KB |
Output is correct |
5 |
Correct |
839 ms |
33364 KB |
Output is correct |
6 |
Correct |
329 ms |
33364 KB |
Output is correct |
7 |
Correct |
151 ms |
33364 KB |
Output is correct |
8 |
Correct |
30 ms |
33364 KB |
Output is correct |
9 |
Correct |
802 ms |
33364 KB |
Output is correct |
10 |
Correct |
738 ms |
33364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
817 ms |
33364 KB |
Output is correct |
2 |
Correct |
820 ms |
33364 KB |
Output is correct |
3 |
Correct |
540 ms |
33364 KB |
Output is correct |
4 |
Correct |
806 ms |
33364 KB |
Output is correct |
5 |
Correct |
865 ms |
33364 KB |
Output is correct |
6 |
Correct |
588 ms |
33364 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 |
408 KB |
Output is correct |
4 |
Correct |
2 ms |
408 KB |
Output is correct |
5 |
Correct |
3 ms |
456 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
3 ms |
544 KB |
Output is correct |
11 |
Correct |
3 ms |
544 KB |
Output is correct |
12 |
Correct |
2 ms |
544 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
3 ms |
748 KB |
Output is correct |
17 |
Correct |
3 ms |
748 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
19 |
Correct |
10 ms |
1132 KB |
Output is correct |
20 |
Correct |
9 ms |
1132 KB |
Output is correct |
21 |
Correct |
9 ms |
1164 KB |
Output is correct |
22 |
Correct |
16 ms |
1164 KB |
Output is correct |
23 |
Correct |
9 ms |
1164 KB |
Output is correct |
24 |
Correct |
9 ms |
1164 KB |
Output is correct |
25 |
Correct |
10 ms |
1164 KB |
Output is correct |
26 |
Correct |
11 ms |
1164 KB |
Output is correct |
27 |
Correct |
17 ms |
33364 KB |
Output is correct |
28 |
Correct |
15 ms |
33364 KB |
Output is correct |
29 |
Correct |
15 ms |
33364 KB |
Output is correct |
30 |
Correct |
18 ms |
33364 KB |
Output is correct |
31 |
Correct |
19 ms |
33364 KB |
Output is correct |
32 |
Correct |
19 ms |
33364 KB |
Output is correct |
33 |
Correct |
160 ms |
33364 KB |
Output is correct |
34 |
Correct |
181 ms |
33364 KB |
Output is correct |
35 |
Correct |
195 ms |
33364 KB |
Output is correct |
36 |
Correct |
221 ms |
33364 KB |
Output is correct |
37 |
Correct |
228 ms |
33364 KB |
Output is correct |
38 |
Correct |
244 ms |
33364 KB |
Output is correct |
39 |
Correct |
468 ms |
33364 KB |
Output is correct |
40 |
Correct |
409 ms |
33364 KB |
Output is correct |
41 |
Correct |
347 ms |
33364 KB |
Output is correct |
42 |
Correct |
175 ms |
33364 KB |
Output is correct |
43 |
Correct |
191 ms |
33364 KB |
Output is correct |
44 |
Correct |
203 ms |
33364 KB |
Output is correct |
45 |
Correct |
191 ms |
33364 KB |
Output is correct |
46 |
Correct |
193 ms |
33364 KB |
Output is correct |
47 |
Correct |
195 ms |
33364 KB |
Output is correct |
48 |
Correct |
177 ms |
33364 KB |
Output is correct |
49 |
Correct |
174 ms |
33364 KB |
Output is correct |
50 |
Correct |
204 ms |
33364 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 |
408 KB |
Output is correct |
4 |
Correct |
2 ms |
408 KB |
Output is correct |
5 |
Correct |
3 ms |
456 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
3 ms |
544 KB |
Output is correct |
11 |
Correct |
3 ms |
544 KB |
Output is correct |
12 |
Correct |
2 ms |
544 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
3 ms |
748 KB |
Output is correct |
17 |
Correct |
3 ms |
748 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
19 |
Correct |
10 ms |
1132 KB |
Output is correct |
20 |
Correct |
9 ms |
1132 KB |
Output is correct |
21 |
Correct |
9 ms |
1164 KB |
Output is correct |
22 |
Correct |
16 ms |
1164 KB |
Output is correct |
23 |
Correct |
9 ms |
1164 KB |
Output is correct |
24 |
Correct |
9 ms |
1164 KB |
Output is correct |
25 |
Correct |
10 ms |
1164 KB |
Output is correct |
26 |
Correct |
11 ms |
1164 KB |
Output is correct |
27 |
Correct |
521 ms |
33364 KB |
Output is correct |
28 |
Correct |
543 ms |
33364 KB |
Output is correct |
29 |
Correct |
571 ms |
33364 KB |
Output is correct |
30 |
Correct |
640 ms |
33364 KB |
Output is correct |
31 |
Correct |
549 ms |
33364 KB |
Output is correct |
32 |
Correct |
715 ms |
33364 KB |
Output is correct |
33 |
Correct |
726 ms |
33364 KB |
Output is correct |
34 |
Correct |
609 ms |
33364 KB |
Output is correct |
35 |
Correct |
2 ms |
33364 KB |
Output is correct |
36 |
Correct |
237 ms |
33364 KB |
Output is correct |
37 |
Correct |
859 ms |
33364 KB |
Output is correct |
38 |
Correct |
787 ms |
33364 KB |
Output is correct |
39 |
Correct |
839 ms |
33364 KB |
Output is correct |
40 |
Correct |
329 ms |
33364 KB |
Output is correct |
41 |
Correct |
151 ms |
33364 KB |
Output is correct |
42 |
Correct |
30 ms |
33364 KB |
Output is correct |
43 |
Correct |
802 ms |
33364 KB |
Output is correct |
44 |
Correct |
738 ms |
33364 KB |
Output is correct |
45 |
Correct |
817 ms |
33364 KB |
Output is correct |
46 |
Correct |
820 ms |
33364 KB |
Output is correct |
47 |
Correct |
540 ms |
33364 KB |
Output is correct |
48 |
Correct |
806 ms |
33364 KB |
Output is correct |
49 |
Correct |
865 ms |
33364 KB |
Output is correct |
50 |
Correct |
588 ms |
33364 KB |
Output is correct |
51 |
Correct |
17 ms |
33364 KB |
Output is correct |
52 |
Correct |
15 ms |
33364 KB |
Output is correct |
53 |
Correct |
15 ms |
33364 KB |
Output is correct |
54 |
Correct |
18 ms |
33364 KB |
Output is correct |
55 |
Correct |
19 ms |
33364 KB |
Output is correct |
56 |
Correct |
19 ms |
33364 KB |
Output is correct |
57 |
Correct |
160 ms |
33364 KB |
Output is correct |
58 |
Correct |
181 ms |
33364 KB |
Output is correct |
59 |
Correct |
195 ms |
33364 KB |
Output is correct |
60 |
Correct |
221 ms |
33364 KB |
Output is correct |
61 |
Correct |
228 ms |
33364 KB |
Output is correct |
62 |
Correct |
244 ms |
33364 KB |
Output is correct |
63 |
Correct |
468 ms |
33364 KB |
Output is correct |
64 |
Correct |
409 ms |
33364 KB |
Output is correct |
65 |
Correct |
347 ms |
33364 KB |
Output is correct |
66 |
Correct |
175 ms |
33364 KB |
Output is correct |
67 |
Correct |
191 ms |
33364 KB |
Output is correct |
68 |
Correct |
203 ms |
33364 KB |
Output is correct |
69 |
Correct |
191 ms |
33364 KB |
Output is correct |
70 |
Correct |
193 ms |
33364 KB |
Output is correct |
71 |
Correct |
195 ms |
33364 KB |
Output is correct |
72 |
Correct |
177 ms |
33364 KB |
Output is correct |
73 |
Correct |
174 ms |
33364 KB |
Output is correct |
74 |
Correct |
204 ms |
33364 KB |
Output is correct |
75 |
Correct |
602 ms |
33364 KB |
Output is correct |
76 |
Correct |
537 ms |
33364 KB |
Output is correct |
77 |
Correct |
600 ms |
33364 KB |
Output is correct |
78 |
Correct |
574 ms |
33364 KB |
Output is correct |
79 |
Correct |
619 ms |
33364 KB |
Output is correct |
80 |
Correct |
583 ms |
33364 KB |
Output is correct |
81 |
Correct |
933 ms |
33364 KB |
Output is correct |
82 |
Correct |
803 ms |
33364 KB |
Output is correct |
83 |
Correct |
810 ms |
33364 KB |
Output is correct |
84 |
Correct |
856 ms |
33364 KB |
Output is correct |
85 |
Correct |
828 ms |
33364 KB |
Output is correct |
86 |
Correct |
860 ms |
33364 KB |
Output is correct |
87 |
Correct |
941 ms |
33364 KB |
Output is correct |
88 |
Correct |
1545 ms |
33364 KB |
Output is correct |
89 |
Correct |
1539 ms |
33364 KB |
Output is correct |
90 |
Correct |
1737 ms |
33364 KB |
Output is correct |
91 |
Correct |
1752 ms |
33364 KB |
Output is correct |
92 |
Correct |
1571 ms |
33364 KB |
Output is correct |
93 |
Correct |
1952 ms |
33364 KB |
Output is correct |
94 |
Execution timed out |
3049 ms |
33364 KB |
Time limit exceeded |
95 |
Halted |
0 ms |
0 KB |
- |