Submission #1073876

# Submission time Handle Problem Language Result Execution time Memory
1073876 2024-08-25T01:28:27 Z ngrace Circle selection (APIO18_circle_selection) C++14
100 / 100
2120 ms 53852 KB
#include <bits/stdc++.h>
using namespace std;
#define v vector
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second

struct Circle{
    ll x, y, r, i;
};

int N;
v<Circle> C;

bool compC(Circle& a, Circle& b){
    if(a.r==b.r) return a.i<b.i;
    return a.r>b.r;
}
bool isect(Circle& a, Circle& b){
    ll dx=a.x-b.x;
    ll dy=a.y-b.y;
    ll r=a.r+b.r;
    return dx*dx+dy*dy <= r*r;
}

v<ll> eBy;

void sub1(){
    for(int i=0; i<N; i++){
        if(eBy[C[i].i]!=-1) continue;
        eBy[C[i].i] = C[i].i;
        for(int j=i+1; j<N; j++){
            if(eBy[C[j].i]==-1 && isect(C[i], C[j])){
                eBy[C[j].i] = C[i].i;
            }
        }
    }
}

void sub2(){
    set<ii> pts;
    for(int i=0; i<N; i++){
        pts.insert(make_pair(C[i].x-C[i].r, i));
        pts.insert(make_pair(C[i].x+C[i].r, i));
    }

    for(int i=0; i<N; i++){
        if(eBy[C[i].i]!=-1) continue;
        v<int> del;
        auto it = pts.lower_bound(make_pair(C[i].x-C[i].r, -1));
        while(it!=pts.end() && (*it).fi<=C[i].x+C[i].r){
            del.push_back((*it).se);
            it++;
        }
        for(int ind:del){
            eBy[C[ind].i] = C[i].i;
            pts.erase(make_pair(C[ind].x-C[ind].r, ind));
            pts.erase(make_pair(C[ind].x+C[ind].r, ind));
        }
    }
}

void sub3(){
    set<ii> xs;
    set<ii> ys;
    for(int i=0; i<N; i++){
        ys.insert({C[i].y-C[i].r, i});
        ys.insert({C[i].y+C[i].r, i});
        eBy[i] = i;
    }
    for(ii y:ys){
        ll x = C[y.se].x;

        if(C[y.se].y+C[y.se].r==y.fi) xs.erase({x,y.se});

        auto it = xs.lower_bound({x,-1});
        if(it!=xs.end()){
            ll ind = (*it).se;
            if(isect(C[y.se], C[ind])){
                ll e = (compC(C[y.se], C[ind]) ? y.se : ind);
                eBy[C[y.se].i] = C[e].i;
                eBy[C[ind].i] = C[e].i;
            }
        }
        if(it!=xs.begin()){
            it--;
            ll ind = (*it).se;
            if(isect(C[y.se], C[ind])){
                ll e = (compC(C[y.se], C[ind]) ? y.se : ind);
                eBy[C[y.se].i] = C[e].i;
                eBy[C[ind].i] = C[e].i;
            }
        }

        if(C[y.se].y-C[y.se].r == y.fi) xs.insert({x,y.se});
    }
}

void sub4(){
    map<ii, v<ll>> grid;
    for(int i=0; i<N; i++){
        C[i].x+=1e9;
        C[i].y+=1e9;
        grid[{C[i].x/C[i].r, C[i].y/C[i].r}].push_back(i);
    }
    for(int i=0; i<N; i++){
        Circle& cur = C[i];
        if(eBy[cur.i]!=-1) continue;
        for(ll x=cur.x/cur.r - 2; x<=cur.x/cur.r+2; x++){
            for(ll y=cur.y/cur.r-2; y<=cur.y/cur.r+2; y++){
                if(grid.find({x,y})==grid.end()) continue;
                for(ll c:grid[{x,y}]){
                    if(eBy[C[c].i]==-1 && isect(C[c],cur)) eBy[C[c].i] = cur.i;
                }
            }
        }
    }
}

void full(){
    map<ii, v<ll>> grid;
    for(int i=0; i<N; i++){
        C[i].x+=1e9;
        C[i].y+=1e9;
    }
    for(ll ri = 30; ri>=0; ri--){
        ll r = (1<<ri);
        bool skip=true;
        for(int i=0; i<N; i++){
            if(eBy[C[i].i]==-1 && C[i].r>=r/2 && C[i].r<=r){
                skip=false;
                break;
            }
        }
        if(skip) continue;
        grid.clear();
        for(int i=0; i<N; i++){
            if(eBy[C[i].i]!=-1) continue;
            grid[{C[i].x/r, C[i].y/r}].push_back(i);
        }
        for(int i=0; i<N; i++){
            Circle& cur = C[i];
            if(cur.r<r/2) break;
            if(eBy[cur.i]!=-1 || cur.r>r) continue;
            for(ll x=cur.x/r - 2; x<=cur.x/r+2; x++){
                for(ll y=cur.y/r-2; y<=cur.y/r+2; y++){
                    if(grid.find({x,y})==grid.end()) continue;
                    for(ll c:grid[{x,y}]){
                        if(eBy[C[c].i]==-1 && isect(C[c],cur)) eBy[C[c].i] = cur.i;
                    }
                }
            }
        }
    }
}

int main(){
    cin>>N;
    bool s2 = true;
    bool s4 = true;
    for(int i=0; i<N; i++){
        ll x,y,r;
        cin>>x>>y>>r;
        C.push_back({x,y,r,i});
        s2 = s2 && y==0;
        s4 = s4 && r==C[0].r;
    }
    sort(C.begin(), C.end(), compC);

    eBy = v<ll>(N,-1);

    if(s4) sub4();
    else full();
    // if(N<=5000) sub1();
    // else if(s2) sub2();
    // else if(s4) sub4();
    // else sub3();

    for(int i:eBy) cout<<i+1<<" ";
    cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 5 ms 736 KB Output is correct
20 Correct 5 ms 668 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 13 ms 984 KB Output is correct
23 Correct 14 ms 1188 KB Output is correct
24 Correct 13 ms 984 KB Output is correct
25 Correct 12 ms 1196 KB Output is correct
26 Correct 15 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 17880 KB Output is correct
2 Correct 251 ms 18408 KB Output is correct
3 Correct 255 ms 19096 KB Output is correct
4 Correct 278 ms 18840 KB Output is correct
5 Correct 268 ms 18144 KB Output is correct
6 Correct 617 ms 28304 KB Output is correct
7 Correct 301 ms 19284 KB Output is correct
8 Correct 373 ms 21656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 401 ms 15772 KB Output is correct
3 Correct 1425 ms 47000 KB Output is correct
4 Correct 1423 ms 47000 KB Output is correct
5 Correct 1458 ms 41348 KB Output is correct
6 Correct 564 ms 20464 KB Output is correct
7 Correct 222 ms 10932 KB Output is correct
8 Correct 34 ms 2592 KB Output is correct
9 Correct 2120 ms 45720 KB Output is correct
10 Correct 1256 ms 38292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1160 ms 47000 KB Output is correct
2 Correct 900 ms 46836 KB Output is correct
3 Correct 460 ms 25500 KB Output is correct
4 Correct 962 ms 46996 KB Output is correct
5 Correct 962 ms 46868 KB Output is correct
6 Correct 354 ms 23996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 5 ms 736 KB Output is correct
20 Correct 5 ms 668 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 13 ms 984 KB Output is correct
23 Correct 14 ms 1188 KB Output is correct
24 Correct 13 ms 984 KB Output is correct
25 Correct 12 ms 1196 KB Output is correct
26 Correct 15 ms 980 KB Output is correct
27 Correct 10 ms 1236 KB Output is correct
28 Correct 9 ms 1256 KB Output is correct
29 Correct 14 ms 1236 KB Output is correct
30 Correct 29 ms 2000 KB Output is correct
31 Correct 28 ms 2004 KB Output is correct
32 Correct 27 ms 2012 KB Output is correct
33 Correct 104 ms 8376 KB Output is correct
34 Correct 103 ms 8376 KB Output is correct
35 Correct 103 ms 8120 KB Output is correct
36 Correct 370 ms 17236 KB Output is correct
37 Correct 355 ms 17336 KB Output is correct
38 Correct 400 ms 17340 KB Output is correct
39 Correct 303 ms 11960 KB Output is correct
40 Correct 295 ms 11956 KB Output is correct
41 Correct 299 ms 11880 KB Output is correct
42 Correct 230 ms 16816 KB Output is correct
43 Correct 262 ms 17080 KB Output is correct
44 Correct 260 ms 17116 KB Output is correct
45 Correct 265 ms 17080 KB Output is correct
46 Correct 267 ms 17080 KB Output is correct
47 Correct 261 ms 17216 KB Output is correct
48 Correct 264 ms 17340 KB Output is correct
49 Correct 282 ms 17332 KB Output is correct
50 Correct 273 ms 17076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 5 ms 736 KB Output is correct
20 Correct 5 ms 668 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 13 ms 984 KB Output is correct
23 Correct 14 ms 1188 KB Output is correct
24 Correct 13 ms 984 KB Output is correct
25 Correct 12 ms 1196 KB Output is correct
26 Correct 15 ms 980 KB Output is correct
27 Correct 246 ms 17880 KB Output is correct
28 Correct 251 ms 18408 KB Output is correct
29 Correct 255 ms 19096 KB Output is correct
30 Correct 278 ms 18840 KB Output is correct
31 Correct 268 ms 18144 KB Output is correct
32 Correct 617 ms 28304 KB Output is correct
33 Correct 301 ms 19284 KB Output is correct
34 Correct 373 ms 21656 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 401 ms 15772 KB Output is correct
37 Correct 1425 ms 47000 KB Output is correct
38 Correct 1423 ms 47000 KB Output is correct
39 Correct 1458 ms 41348 KB Output is correct
40 Correct 564 ms 20464 KB Output is correct
41 Correct 222 ms 10932 KB Output is correct
42 Correct 34 ms 2592 KB Output is correct
43 Correct 2120 ms 45720 KB Output is correct
44 Correct 1256 ms 38292 KB Output is correct
45 Correct 1160 ms 47000 KB Output is correct
46 Correct 900 ms 46836 KB Output is correct
47 Correct 460 ms 25500 KB Output is correct
48 Correct 962 ms 46996 KB Output is correct
49 Correct 962 ms 46868 KB Output is correct
50 Correct 354 ms 23996 KB Output is correct
51 Correct 10 ms 1236 KB Output is correct
52 Correct 9 ms 1256 KB Output is correct
53 Correct 14 ms 1236 KB Output is correct
54 Correct 29 ms 2000 KB Output is correct
55 Correct 28 ms 2004 KB Output is correct
56 Correct 27 ms 2012 KB Output is correct
57 Correct 104 ms 8376 KB Output is correct
58 Correct 103 ms 8376 KB Output is correct
59 Correct 103 ms 8120 KB Output is correct
60 Correct 370 ms 17236 KB Output is correct
61 Correct 355 ms 17336 KB Output is correct
62 Correct 400 ms 17340 KB Output is correct
63 Correct 303 ms 11960 KB Output is correct
64 Correct 295 ms 11956 KB Output is correct
65 Correct 299 ms 11880 KB Output is correct
66 Correct 230 ms 16816 KB Output is correct
67 Correct 262 ms 17080 KB Output is correct
68 Correct 260 ms 17116 KB Output is correct
69 Correct 265 ms 17080 KB Output is correct
70 Correct 267 ms 17080 KB Output is correct
71 Correct 261 ms 17216 KB Output is correct
72 Correct 264 ms 17340 KB Output is correct
73 Correct 282 ms 17332 KB Output is correct
74 Correct 273 ms 17076 KB Output is correct
75 Correct 364 ms 22420 KB Output is correct
76 Correct 303 ms 22436 KB Output is correct
77 Correct 322 ms 22384 KB Output is correct
78 Correct 315 ms 24980 KB Output is correct
79 Correct 367 ms 22640 KB Output is correct
80 Correct 297 ms 25012 KB Output is correct
81 Correct 1521 ms 51164 KB Output is correct
82 Correct 1371 ms 51112 KB Output is correct
83 Correct 1363 ms 51092 KB Output is correct
84 Correct 1503 ms 51232 KB Output is correct
85 Correct 1451 ms 50932 KB Output is correct
86 Correct 1326 ms 51308 KB Output is correct
87 Correct 1642 ms 51020 KB Output is correct
88 Correct 1217 ms 35016 KB Output is correct
89 Correct 1162 ms 34968 KB Output is correct
90 Correct 1202 ms 35180 KB Output is correct
91 Correct 1218 ms 35108 KB Output is correct
92 Correct 1165 ms 35220 KB Output is correct
93 Correct 1203 ms 50448 KB Output is correct
94 Correct 1178 ms 50584 KB Output is correct
95 Correct 1177 ms 50584 KB Output is correct
96 Correct 1415 ms 50640 KB Output is correct
97 Correct 1571 ms 50416 KB Output is correct
98 Correct 769 ms 38100 KB Output is correct
99 Correct 1168 ms 53852 KB Output is correct
100 Correct 1107 ms 53676 KB Output is correct
101 Correct 1047 ms 43156 KB Output is correct
102 Correct 1195 ms 53276 KB Output is correct
103 Correct 1641 ms 52376 KB Output is correct
104 Correct 1118 ms 53660 KB Output is correct
105 Correct 875 ms 51552 KB Output is correct
106 Correct 877 ms 52444 KB Output is correct
107 Correct 919 ms 52632 KB Output is correct
108 Correct 870 ms 52652 KB Output is correct
109 Correct 882 ms 52472 KB Output is correct
110 Correct 880 ms 52464 KB Output is correct
111 Correct 880 ms 52632 KB Output is correct
112 Correct 866 ms 52464 KB Output is correct
113 Correct 933 ms 52628 KB Output is correct
114 Correct 886 ms 52804 KB Output is correct
115 Correct 889 ms 52616 KB Output is correct
116 Correct 838 ms 52640 KB Output is correct