Submission #49076

# Submission time Handle Problem Language Result Execution time Memory
49076 2018-05-21T19:54:45 Z yusufake Circle selection (APIO18_circle_selection) C++
87 / 100
3000 ms 28756 KB
#include<bits/stdc++.h> 
using namespace std; 

#define _   int v, int tl, int tr, int l, int r, ll x
#define tm  (tl + tr >> 1)
#define sol v+v,tl,tm,l,r,x 
#define sag v+v+1,tm+1,tr,l,r,x

#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;
    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]);
    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;
}

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) && !ans[ root->id ])
		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 , p[era[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:30: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:76: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 432 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 9 ms 1132 KB Output is correct
20 Correct 11 ms 1132 KB Output is correct
21 Correct 9 ms 1148 KB Output is correct
22 Correct 13 ms 1148 KB Output is correct
23 Correct 9 ms 1148 KB Output is correct
24 Correct 13 ms 1148 KB Output is correct
25 Correct 8 ms 1148 KB Output is correct
26 Correct 8 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 453 ms 28756 KB Output is correct
2 Correct 469 ms 28756 KB Output is correct
3 Correct 504 ms 28756 KB Output is correct
4 Correct 442 ms 28756 KB Output is correct
5 Correct 518 ms 28756 KB Output is correct
6 Correct 564 ms 28756 KB Output is correct
7 Correct 435 ms 28756 KB Output is correct
8 Correct 497 ms 28756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 28756 KB Output is correct
2 Correct 208 ms 28756 KB Output is correct
3 Correct 724 ms 28756 KB Output is correct
4 Correct 766 ms 28756 KB Output is correct
5 Correct 761 ms 28756 KB Output is correct
6 Correct 294 ms 28756 KB Output is correct
7 Correct 143 ms 28756 KB Output is correct
8 Correct 26 ms 28756 KB Output is correct
9 Correct 740 ms 28756 KB Output is correct
10 Correct 637 ms 28756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 653 ms 28756 KB Output is correct
2 Correct 689 ms 28756 KB Output is correct
3 Correct 539 ms 28756 KB Output is correct
4 Correct 690 ms 28756 KB Output is correct
5 Correct 682 ms 28756 KB Output is correct
6 Correct 438 ms 28756 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 432 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 9 ms 1132 KB Output is correct
20 Correct 11 ms 1132 KB Output is correct
21 Correct 9 ms 1148 KB Output is correct
22 Correct 13 ms 1148 KB Output is correct
23 Correct 9 ms 1148 KB Output is correct
24 Correct 13 ms 1148 KB Output is correct
25 Correct 8 ms 1148 KB Output is correct
26 Correct 8 ms 1148 KB Output is correct
27 Correct 13 ms 28756 KB Output is correct
28 Correct 13 ms 28756 KB Output is correct
29 Correct 13 ms 28756 KB Output is correct
30 Correct 15 ms 28756 KB Output is correct
31 Correct 15 ms 28756 KB Output is correct
32 Correct 17 ms 28756 KB Output is correct
33 Correct 129 ms 28756 KB Output is correct
34 Correct 145 ms 28756 KB Output is correct
35 Correct 141 ms 28756 KB Output is correct
36 Correct 214 ms 28756 KB Output is correct
37 Correct 214 ms 28756 KB Output is correct
38 Correct 171 ms 28756 KB Output is correct
39 Correct 345 ms 28756 KB Output is correct
40 Correct 234 ms 28756 KB Output is correct
41 Correct 265 ms 28756 KB Output is correct
42 Correct 129 ms 28756 KB Output is correct
43 Correct 139 ms 28756 KB Output is correct
44 Correct 140 ms 28756 KB Output is correct
45 Correct 164 ms 28756 KB Output is correct
46 Correct 178 ms 28756 KB Output is correct
47 Correct 176 ms 28756 KB Output is correct
48 Correct 172 ms 28756 KB Output is correct
49 Correct 171 ms 28756 KB Output is correct
50 Correct 176 ms 28756 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 432 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 9 ms 1132 KB Output is correct
20 Correct 11 ms 1132 KB Output is correct
21 Correct 9 ms 1148 KB Output is correct
22 Correct 13 ms 1148 KB Output is correct
23 Correct 9 ms 1148 KB Output is correct
24 Correct 13 ms 1148 KB Output is correct
25 Correct 8 ms 1148 KB Output is correct
26 Correct 8 ms 1148 KB Output is correct
27 Correct 453 ms 28756 KB Output is correct
28 Correct 469 ms 28756 KB Output is correct
29 Correct 504 ms 28756 KB Output is correct
30 Correct 442 ms 28756 KB Output is correct
31 Correct 518 ms 28756 KB Output is correct
32 Correct 564 ms 28756 KB Output is correct
33 Correct 435 ms 28756 KB Output is correct
34 Correct 497 ms 28756 KB Output is correct
35 Correct 2 ms 28756 KB Output is correct
36 Correct 208 ms 28756 KB Output is correct
37 Correct 724 ms 28756 KB Output is correct
38 Correct 766 ms 28756 KB Output is correct
39 Correct 761 ms 28756 KB Output is correct
40 Correct 294 ms 28756 KB Output is correct
41 Correct 143 ms 28756 KB Output is correct
42 Correct 26 ms 28756 KB Output is correct
43 Correct 740 ms 28756 KB Output is correct
44 Correct 637 ms 28756 KB Output is correct
45 Correct 653 ms 28756 KB Output is correct
46 Correct 689 ms 28756 KB Output is correct
47 Correct 539 ms 28756 KB Output is correct
48 Correct 690 ms 28756 KB Output is correct
49 Correct 682 ms 28756 KB Output is correct
50 Correct 438 ms 28756 KB Output is correct
51 Correct 13 ms 28756 KB Output is correct
52 Correct 13 ms 28756 KB Output is correct
53 Correct 13 ms 28756 KB Output is correct
54 Correct 15 ms 28756 KB Output is correct
55 Correct 15 ms 28756 KB Output is correct
56 Correct 17 ms 28756 KB Output is correct
57 Correct 129 ms 28756 KB Output is correct
58 Correct 145 ms 28756 KB Output is correct
59 Correct 141 ms 28756 KB Output is correct
60 Correct 214 ms 28756 KB Output is correct
61 Correct 214 ms 28756 KB Output is correct
62 Correct 171 ms 28756 KB Output is correct
63 Correct 345 ms 28756 KB Output is correct
64 Correct 234 ms 28756 KB Output is correct
65 Correct 265 ms 28756 KB Output is correct
66 Correct 129 ms 28756 KB Output is correct
67 Correct 139 ms 28756 KB Output is correct
68 Correct 140 ms 28756 KB Output is correct
69 Correct 164 ms 28756 KB Output is correct
70 Correct 178 ms 28756 KB Output is correct
71 Correct 176 ms 28756 KB Output is correct
72 Correct 172 ms 28756 KB Output is correct
73 Correct 171 ms 28756 KB Output is correct
74 Correct 176 ms 28756 KB Output is correct
75 Correct 440 ms 28756 KB Output is correct
76 Correct 441 ms 28756 KB Output is correct
77 Correct 480 ms 28756 KB Output is correct
78 Correct 501 ms 28756 KB Output is correct
79 Correct 528 ms 28756 KB Output is correct
80 Correct 522 ms 28756 KB Output is correct
81 Correct 762 ms 28756 KB Output is correct
82 Correct 795 ms 28756 KB Output is correct
83 Correct 692 ms 28756 KB Output is correct
84 Correct 781 ms 28756 KB Output is correct
85 Correct 763 ms 28756 KB Output is correct
86 Correct 759 ms 28756 KB Output is correct
87 Correct 806 ms 28756 KB Output is correct
88 Correct 1396 ms 28756 KB Output is correct
89 Correct 1368 ms 28756 KB Output is correct
90 Correct 1282 ms 28756 KB Output is correct
91 Correct 1018 ms 28756 KB Output is correct
92 Correct 1282 ms 28756 KB Output is correct
93 Correct 1334 ms 28756 KB Output is correct
94 Execution timed out 3037 ms 28756 KB Time limit exceeded
95 Halted 0 ms 0 KB -