Submission #217676

# Submission time Handle Problem Language Result Execution time Memory
217676 2020-03-30T12:10:01 Z VEGAnn Circle selection (APIO18_circle_selection) C++14
19 / 100
3000 ms 48000 KB
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define PB push_back
#define pii pair<int,int>
#define ft first
#define sd second
#define MP make_pair
using namespace std;
typedef long long ll;
const int N = 300100;
const int M = 200100;
const int oo = 2e9 + 7;
set<pii, greater<pii> > bst;
vector<int> xs;
int x[N], y[N], r[N], n, mrk[N], nm[N], obr[N];
pii st[2][4 * N], BAD = MP(-oo, -oo);

ll sqr(ll x){ return (x * x);}

bool cmp(int _x, int _y){
    return x[_x] < x[_y];
}

void build(int v, int l, int r1){
    if (l == r1){
        st[0][v] = MP(r[nm[l]] + x[nm[l]], nm[l]);
        st[1][v] = MP(r[nm[l]] - x[nm[l]], nm[l]);
        bst.insert(MP(r[nm[l]], -nm[l]));
        return;
    }

    int md = (l + r1) >> 1;
    build(v + v, l, md);
    build(v + v + 1, md + 1, r1);

    st[0][v] = max(st[0][v + v], st[0][v + v + 1]);
    st[1][v] = max(st[1][v + v], st[1][v + v + 1]);
}

void update(int v, int l, int r, int ps){
    if (l == r){
        st[0][v] = st[1][v] = BAD;
        return;
    }
    int md = (l + r) >> 1;

    if (ps <= md)
        update(v + v, l, md, ps);
    else update(v + v + 1, md + 1, r, ps);

    st[0][v] = max(st[0][v + v], st[0][v + v + 1]);
    st[1][v] = max(st[1][v + v], st[1][v + v + 1]);
}

pii get(int tp, int v, int tl, int tr, int l, int r){
    if (l > r) return BAD;
    if (tl == l && tr == r) return st[tp][v];

    int md = (tl + tr) >> 1;
    return max(get(tp, v + v, tl, md, l, min(r, md)),
               get(tp, v + v + 1, md + 1, tr, max(md + 1, l), r));
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

//    freopen("in.txt","r",stdin);

    cin >> n;

    bool ok = 1;

    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> r[i];
        xs.PB(x[i]);
        nm[i] = i;
        ok &= bool(y[i] == 0);
    }

    fill(mrk, mrk + n, -1);

    if (ok){
        sort(nm, nm + n, cmp);
        sort(all(xs));

        bst.clear();
        build(1, 0, n - 1);

        for (int i = 0; i < n; i++)
            obr[nm[i]] = i;

        while (sz(bst) > 0){
            pii CUR = (*bst.begin());
            bst.erase(bst.begin());
            int mx = CUR.ft, nm = -CUR.sd;
            mrk[nm] = nm;

            update(1, 0, n - 1, obr[nm]);

            int loc = lower_bound(all(xs), x[nm]) - xs.begin();

            while (1){
                pii cr = get(0, 1, 0, n - 1, 0, loc - 1);

                if (cr.ft < -r[nm] + x[nm]) break;

                bst.erase(MP(r[cr.sd], -cr.sd));
                mrk[cr.sd] = nm;
                update(1, 0, n - 1, obr[cr.sd]);
            }

            while (1){
                pii cr = get(1, 1, 0, n - 1, loc, n - 1);

                if (cr.ft < -r[nm] - x[nm]) break;

                bst.erase(MP(r[cr.sd], -cr.sd));
                mrk[cr.sd] = nm;
                update(1, 0, n - 1, obr[cr.sd]);
            }
        }

        for (int i = 0; i < n; i++)
            cout << mrk[i] + 1 << " ";
        return 0;
    }

    int kol = n;

    for (; kol > 0; ){
        int nom = -1, mx = -1;

        for (int i = 0; i < n; i++){
            if (mrk[i] >= 0) continue;

            if (r[i] > mx){
                mx = r[i];
                nom = i;
            }
        }

        for (int i = 0; i < n; i++){
            if (mrk[i] >= 0) continue;

            ll cur = sqr(x[i] - x[nom]) + sqr(y[i] - y[nom]) - sqr(r[i] + r[nom]);

            if (cur <= 0){
                mrk[i] = nom;
                kol--;
            }
        }
    }

    for (int i = 0; i < n; i++)
        cout << mrk[i] + 1 << " ";

    return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:96:17: warning: unused variable 'mx' [-Wunused-variable]
             int mx = CUR.ft, nm = -CUR.sd;
                 ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 7 ms 512 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 159 ms 512 KB Output is correct
23 Correct 157 ms 512 KB Output is correct
24 Correct 161 ms 512 KB Output is correct
25 Correct 156 ms 512 KB Output is correct
26 Correct 156 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 868 ms 41252 KB Output is correct
2 Correct 821 ms 48000 KB Output is correct
3 Correct 856 ms 47596 KB Output is correct
4 Correct 910 ms 47976 KB Output is correct
5 Correct 753 ms 45672 KB Output is correct
6 Correct 845 ms 45824 KB Output is correct
7 Correct 767 ms 45832 KB Output is correct
8 Correct 759 ms 45928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 3080 ms 2804 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3077 ms 7532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 7 ms 512 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 159 ms 512 KB Output is correct
23 Correct 157 ms 512 KB Output is correct
24 Correct 161 ms 512 KB Output is correct
25 Correct 156 ms 512 KB Output is correct
26 Correct 156 ms 512 KB Output is correct
27 Correct 10 ms 768 KB Output is correct
28 Correct 12 ms 768 KB Output is correct
29 Correct 11 ms 836 KB Output is correct
30 Correct 694 ms 712 KB Output is correct
31 Correct 676 ms 712 KB Output is correct
32 Correct 698 ms 724 KB Output is correct
33 Correct 60 ms 3496 KB Output is correct
34 Correct 58 ms 3456 KB Output is correct
35 Correct 70 ms 3460 KB Output is correct
36 Execution timed out 3068 ms 2932 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 7 ms 512 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 159 ms 512 KB Output is correct
23 Correct 157 ms 512 KB Output is correct
24 Correct 161 ms 512 KB Output is correct
25 Correct 156 ms 512 KB Output is correct
26 Correct 156 ms 512 KB Output is correct
27 Correct 868 ms 41252 KB Output is correct
28 Correct 821 ms 48000 KB Output is correct
29 Correct 856 ms 47596 KB Output is correct
30 Correct 910 ms 47976 KB Output is correct
31 Correct 753 ms 45672 KB Output is correct
32 Correct 845 ms 45824 KB Output is correct
33 Correct 767 ms 45832 KB Output is correct
34 Correct 759 ms 45928 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Execution timed out 3080 ms 2804 KB Time limit exceeded
37 Halted 0 ms 0 KB -