Submission #49100

# Submission time Handle Problem Language Result Execution time Memory
49100 2018-05-22T05:44:11 Z BThero Circle selection (APIO18_circle_selection) C++17
12 / 100
953 ms 22432 KB
// Why am I so stupid? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

typedef long long ll;

using namespace std;

const int MAXN = 3e5+5;

struct circle {
    int x, y, r, id;
    int L, R;

    circle() {
        x = y = r = id = 0;
        L = R = 0;
    }
} arr[MAXN];

bool col[MAXN << 3];

int t[MAXN << 3];

int ans[MAXN];

int n, m;

void compress() {
    vector <int> vv;

    for (int i = 1; i <= n; ++i) {
        vv.pb(arr[i].x - arr[i].r);
        vv.pb(arr[i].x + arr[i].r);
    }

    sort(all(vv));
    vv.resize(unique(all(vv)) - vv.begin());

    m = vv.size();

    for (int i = 1; i <= n; ++i) {
        arr[i].L = upper_bound(all(vv), arr[i].x - arr[i].r) - vv.begin();
        arr[i].R = upper_bound(all(vv), arr[i].x + arr[i].r) - vv.begin();
    }
}

bool cmp(circle a, circle b) {
    if (a.r == b.r) {
        return a.id < b.id;
    }

    return a.r > b.r;
}

bool inter(circle a, circle b) {
    ll d = (a.x - b.x) * 1ll * (a.x - b.x) + (a.y - b.y) * 1ll * (a.y - b.y);
    return d <= (a.r + b.r) * 1ll * (a.r + b.r);
}

void push(int v, int tl, int tr) {
    if (col[v] && tl != tr) {
        if (!col[v + v]) {
            col[v + v] = 1;
            t[v + v] = t[v];
        }

        if (!col[v + v + 1]) {
            col[v + v + 1] = 1;
            t[v + v + 1] = t[v];
        }
    }
}

int segMin(int v, int tl, int tr, int l, int r) {
    push(v, tl, tr);

    if (l > r || tl > r || tr < l) {
        return MAXN;
    }

    if (l <= tl && tr <= r) {
        return t[v];
    }

    int mid = (tl + tr) >> 1;
    int c1 = (v << 1), c2 = (c1 | 1);

    return min(
        segMin(c1, tl, mid, l, r),
        segMin(c2, mid + 1, tr, l, r)
    );
}

void segUpd(int v, int tl, int tr, int l, int r, int x) {
    push(v, tl, tr);

    if (l > r || tl > r || tr < l) {
        return;
    }

    if (l <= tl && tr <= r && !col[v]) {
        col[v] = 1; t[v] = min(t[v], x);
        push(v, tl, tr);

        return;
    }

    int mid = (tl + tr) >> 1;
    int c1 = (v << 1), c2 = (c1 | 1);

    segUpd(c1, tl, mid, l, r, x);
    segUpd(c2, mid + 1, tr, l, r, x);

    t[v] = min(t[c1], t[c2]);
    col[v] = (col[c1] & col[c2]);
}

void solve() {
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
        scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r);
        arr[i].id = i;
    }

    compress();

    sort(arr + 1, arr + n + 1, cmp);

    for (int i = 1; i <= (m << 2); ++i) {
        t[i] = MAXN;
    }

    for (int i = 1; i <= n; ++i) {
        int cur = segMin(1, 1, m, arr[i].L, arr[i].R);

        if (cur <= n) {
            ans[arr[i].id] = arr[cur].id;
        }
        else {
            ans[arr[i].id] = arr[i].id;
            segUpd(1, 1, m, arr[i].L, arr[i].R, i);
        }
    }

    for (int i = 1; i <= n; ++i) {
        printf("%d ", ans[i]);
    }
}

int main() {
#ifdef BThero
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // BThero

    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

circle_selection.cpp: In function 'void solve()':
circle_selection.cpp:127:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
circle_selection.cpp:130:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7288 KB Output is correct
2 Correct 7 ms 7396 KB Output is correct
3 Incorrect 8 ms 7448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 953 ms 22156 KB Output is correct
2 Correct 887 ms 22432 KB Output is correct
3 Correct 843 ms 22432 KB Output is correct
4 Correct 815 ms 22432 KB Output is correct
5 Correct 609 ms 22432 KB Output is correct
6 Correct 700 ms 22432 KB Output is correct
7 Correct 673 ms 22432 KB Output is correct
8 Correct 712 ms 22432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 22432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 623 ms 22432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7288 KB Output is correct
2 Correct 7 ms 7396 KB Output is correct
3 Incorrect 8 ms 7448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7288 KB Output is correct
2 Correct 7 ms 7396 KB Output is correct
3 Incorrect 8 ms 7448 KB Output isn't correct
4 Halted 0 ms 0 KB -