답안 #402462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402462 2021-05-11T17:45:37 Z teehandsome 원 고르기 (APIO18_circle_selection) C++11
0 / 100
1209 ms 58664 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}

void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
    _print(H);
    if(sizeof...(T)) cerr<<",";
    else cerr<<"\"]";
    dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct dt {
    ll l,r;
    int idx;
//    dt(ll L,ll R,int IDX) {
//        l=L,r=R,idx=IDX;
//    }
    bool intersect(const dt &rr) {
        if(rr.l>=l and rr.l<=r) return true;
        if(rr.r>=l and rr.r<=r) return true;
        return false;
    }
};
struct cmpL {
    bool operator()(const dt &l,const dt &r) {
        if(l.l==r.l) return l.r>r.r;
        return l.l<r.l;
    }
};
struct cmpR {
    bool operator()(const dt &l,const dt &r) {
        if(l.r==r.r) return l.l>r.l;
        return l.r<r.r;
    }
};

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    vector<dt> a(n);
    set<dt,cmpL> sL;
    set<dt,cmpR> sR;
    for(int i=0;i<n;i++) {
        int x,y,r; cin>>x>>y>>r;
        a[i]={x-r,x+r,i};
        sL.insert(a[i]);
        sR.insert(a[i]);
    }
    sort(all(a),[&](const dt &l,const dt &r) {
            if((l.r-l.l)==(r.r-r.l)) return l.l<r.l;
            return (l.r-l.l)>(r.r-r.l);
         });
    vector<int> ans(n,-1);
    for(int i=0;i<n;i++) {
        int u=a[i].idx;
        if(ans[u]!=-1) continue;
        auto p=sL.lower_bound(a[i]);
        vector<dt> to_del;
        while(p!=sL.end()) {
            int v=p->idx;
            if(ans[v]!=-1) continue;
            if(!a[i].intersect(*p)) break;
            to_del.push_back(*p);
//            sL.erase(p); sR.erase(p);
            ans[v]=u; p++;
        }
        for(auto e:to_del) sL.erase(e),sR.erase(e);

        vector<dt> to_del2;
        auto p2=sR.upper_bound(a[i]);
        if(p2!=sR.begin()) --p2;
        while(p2!=sR.begin()) {
            int v=p2->idx;
            if(ans[v]!=-1) continue;
            if(!a[i].intersect(*p2)) break;
            to_del2.push_back(*p2);
//            sL.erase(p2); sR.erase(p2);
            ans[v]=u; p2--;
        }
        for(auto e:to_del2) sL.erase(e),sR.erase(e);
    }
    for(int i=0;i<n;i++) cout<<ans[i]+1<<" ";
    cout<<endl;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1209 ms 58664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 612 ms 48056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -