Submission #1087896

# Submission time Handle Problem Language Result Execution time Memory
1087896 2024-09-13T11:19:28 Z alexander707070 Circle selection (APIO18_circle_selection) C++14
12 / 100
816 ms 58552 KB
#include<bits/stdc++.h>
#define MAXN 600007
using namespace std;

int n,par[MAXN],cnt;
long long x[MAXN],y[MAXN],r[MAXN];
pair<int,int> p[MAXN];

map<int,int> mp;
vector<int> w;

int tree[4*MAXN];

void update(int v,int l,int r,int ll,int rr,int val){
    if(ll>rr)return;
    if(l==ll and r==rr){
        tree[v]=val;
    }else{
        int tt=(l+r)/2;

        if(tree[v]!=0){
            tree[2*v]=tree[2*v+1]=tree[v];
            tree[v]=0;
        }

        update(2*v,l,tt,ll,min(tt,rr),val);
        update(2*v+1,tt+1,r,max(tt+1,ll),rr,val);
    }
}

int getpos(int v,int l,int r,int pos){
    if(l==r)return tree[v];

    int tt=(l+r)/2;

    if(tree[v]!=0){
        tree[2*v]=tree[2*v+1]=tree[v];
        tree[v]=0;
    }

    if(pos<=tt)return getpos(2*v,l,tt,pos);
    return getpos(2*v+1,tt+1,r,pos);
}

int main(){

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>y[i]>>r[i];

        w.push_back(x[i]-r[i]);
        w.push_back(x[i]+r[i]);

        p[i]={r[i],-i};
    }

    sort(w.begin(),w.end());

    for(int i=0;i<w.size();i++){
        if(i==0 or w[i]!=w[i-1])cnt++;
        mp[w[i]]=cnt;
    }

    sort(p+1,p+n+1);

    for(int i=n;i>=1;i--){
        int curr=-p[i].second;
        
        int le=getpos(1,1,cnt,mp[x[curr]-r[curr]]);
        int re=getpos(1,1,cnt,mp[x[curr]+r[curr]]);
        
        if(le!=0 or re!=0){
            if(r[le]>r[re])par[curr]=le;
            else if(r[le]<r[re])par[curr]=re;
            else par[curr]=min(le,re);

            continue;
        }

        par[curr]=curr;
        update(1,1,cnt,mp[x[curr]-r[curr]],mp[x[curr]+r[curr]],curr);
    }

    for(int i=1;i<=n;i++){
        cout<<par[i]<<" ";
    }
    cout<<"\n";

    return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 780 ms 57164 KB Output is correct
2 Correct 816 ms 57600 KB Output is correct
3 Correct 797 ms 57780 KB Output is correct
4 Correct 777 ms 57396 KB Output is correct
5 Correct 539 ms 37556 KB Output is correct
6 Correct 682 ms 55600 KB Output is correct
7 Correct 688 ms 53084 KB Output is correct
8 Correct 650 ms 54300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 705 ms 58552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -