Submission #737190

#TimeUsernameProblemLanguageResultExecution timeMemory
737190Username4132Circle selection (APIO18_circle_selection)C++14
100 / 100
1885 ms49220 KiB
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
using pii=pair<int, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)


struct circle{
    int x, y, r, ind;
    circle(int X=0, int Y=0, int R=0) : x(X), y(Y), r(R){}
};

bool operator< (circle a, circle b){
    return a.r!=b.r? a.r>b.r : a.ind<b.ind;
}

const int MAXN=300010, LOG=32, dif[3]={-1, 0, 1};
int n, ans[MAXN];
circle arr[MAXN];
map<pii, vector<circle>> cir[LOG];

bool inters(circle a, circle b){
    long long dx=a.x-b.x, dy=a.y-b.y, sr=a.r+b.r;
    return dx*dx <= sr*sr - dy*dy;
}

void insert(circle c){
    int k=8*sizeof(int)-__builtin_clz(c.r);
    cir[k][{c.x>>(k+1), c.y>>(k+1)}].push_back(c);
}

int check(circle c){
    circle ret; ret.ind=-1;
    forn(k, LOG){
        int nx=c.x>>(k+1), ny=c.y>>(k+1);
        forn(i, 3) forn(j, 3){
            auto itr=cir[k].find({nx+dif[i], ny+dif[j]});
            if(itr!=cir[k].end()) for(auto cr:(itr->second)) if(inters(c, cr)) ret=min(ret, cr);
        }
    }
    return ret.ind;
}

int main(){
    scanf("%d", &n);
    forn(i, n) scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r), arr[i].ind=i;
    sort(arr, arr+n);
    forn(i, n){
        int val = check(arr[i]);
        if(val==-1){
            ans[arr[i].ind]=arr[i].ind;
            insert(arr[i]);
        }
        else ans[arr[i].ind]=val;
    }
    forn(i, n) printf("%d ", ans[i]+1);
}

Compilation message (stderr)

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:48:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     forn(i, n) scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r), arr[i].ind=i;
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...