답안 #403846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403846 2021-05-13T14:11:32 Z rqi 원 고르기 (APIO18_circle_selection) C++14
19 / 100
865 ms 58992 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pl;
typedef vector<int> vi;

#define f first
#define s second
#define pb push_back
#define all(x) begin(x), end(x)
#define mp make_pair
#define lb lower_bound
#define ins insert

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct hashFunc{
    size_t operator()(const pl& a)const {
        return a.f ^(a.s+1);
    }
};

const int mx = 300005;
int n;
ll x[mx];
ll y[mx];
ll r[mx];
bool present[mx];
int ans[mx];

bool circleIntersect(int a, int b){
    ll dist = (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
    if(dist <= (r[a]+r[b])*(r[a]+r[b])) return 1;
    return 0;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    //gp_hash_table<pl, vi, hashFunc> g;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> y[i] >> r[i];
    }
    vector<pair<ll, int>> v;
    for(int i = 1; i <= n; i++){
        v.pb(mp(-r[i], i));
    }
    sort(all(v));
    vi inds;
    for(int i = 0; i < n; i++){
        inds.pb(v[i].s);
    }

    if(n <= 5000){
        for(int i = 1; i <= n; i++){
            present[i] = 1;
        }
        for(auto ind: inds){
            if(present[ind]){
                present[ind] = 0;
                ans[ind] = ind;
                for(int i = 1; i <= n; i++){
                    if(present[i] && circleIntersect(i, ind)){
                        present[i] = 0;
                        ans[i] = ind;
                    }
                }
            }
            
        }
        for(int i = 1; i <= n; i++){
            cout << ans[i] << " ";
        }
        cout << "\n";
        exit(0);
    }

    bool allYs = 1;
    for(int i = 1; i <= n; i++){
        if(y[i] != 0){
            allYs = 0;
        }
    }
    if(allYs){
        set<pair<ll, int>> lefts;
        set<pair<ll, int>> rights;
        for(auto ind: inds){
            lefts.ins(mp(x[ind]-r[ind], ind));
            rights.ins(mp(x[ind]+r[ind], ind));
        }

        for(int i = 1; i <= n; i++){
            present[i] = 1;
        }
        for(auto ind: inds){
            //cout << "ind: " << ind << "\n";
            if(!present[ind]) continue;
            present[ind] = 0;
            ans[ind] = ind;
            //cout << "LEFTS: " << "\n";
            while(true){
                auto it = lefts.lb(mp(x[ind]-r[ind], 0));
                if(it == lefts.end()) break;
                if(it->f > x[ind]+r[ind]) break;
                int circ_ind = it->s;
                //cout << "circ_ind: " << circ_ind << "\n";
                lefts.erase(it);
                if(!present[circ_ind]) continue;
                //cout << "present" << "\n";
                present[circ_ind] = 0;
                ans[circ_ind] = ind;
            }
            //cout << "RIGHTS: " << "\n";
            while(true){
                auto it = rights.lb(mp(x[ind]+r[ind]+1, 0));
                if(it == rights.begin()) break;
                it = prev(it);
                if(it->f < x[ind]-r[ind]) break;
                int circ_ind = it->s;
                //cout << "circ_ind: " << circ_ind << "\n";
                rights.erase(it);
                if(!present[circ_ind]) continue;
                //cout << "present" << "\n";
                present[circ_ind] = 0;
                ans[circ_ind] = ind;
            }
        }
        for(int i = 1; i <= n; i++){
            cout << ans[i] << " ";
        }
        cout << "\n";
        exit(0);
    }

    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 6 ms 844 KB Output is correct
20 Correct 4 ms 844 KB Output is correct
21 Correct 6 ms 844 KB Output is correct
22 Correct 130 ms 812 KB Output is correct
23 Correct 153 ms 808 KB Output is correct
24 Correct 138 ms 812 KB Output is correct
25 Correct 126 ms 812 KB Output is correct
26 Correct 154 ms 808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 865 ms 54528 KB Output is correct
2 Correct 830 ms 55232 KB Output is correct
3 Correct 784 ms 54972 KB Output is correct
4 Correct 715 ms 55224 KB Output is correct
5 Correct 737 ms 55020 KB Output is correct
6 Correct 864 ms 58888 KB Output is correct
7 Correct 778 ms 58992 KB Output is correct
8 Correct 736 ms 58848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 52 ms 5404 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 140 ms 15848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 6 ms 844 KB Output is correct
20 Correct 4 ms 844 KB Output is correct
21 Correct 6 ms 844 KB Output is correct
22 Correct 130 ms 812 KB Output is correct
23 Correct 153 ms 808 KB Output is correct
24 Correct 138 ms 812 KB Output is correct
25 Correct 126 ms 812 KB Output is correct
26 Correct 154 ms 808 KB Output is correct
27 Incorrect 6 ms 1100 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 6 ms 844 KB Output is correct
20 Correct 4 ms 844 KB Output is correct
21 Correct 6 ms 844 KB Output is correct
22 Correct 130 ms 812 KB Output is correct
23 Correct 153 ms 808 KB Output is correct
24 Correct 138 ms 812 KB Output is correct
25 Correct 126 ms 812 KB Output is correct
26 Correct 154 ms 808 KB Output is correct
27 Correct 865 ms 54528 KB Output is correct
28 Correct 830 ms 55232 KB Output is correct
29 Correct 784 ms 54972 KB Output is correct
30 Correct 715 ms 55224 KB Output is correct
31 Correct 737 ms 55020 KB Output is correct
32 Correct 864 ms 58888 KB Output is correct
33 Correct 778 ms 58992 KB Output is correct
34 Correct 736 ms 58848 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Incorrect 52 ms 5404 KB Output isn't correct
37 Halted 0 ms 0 KB -