Submission #49107

# Submission time Handle Problem Language Result Execution time Memory
49107 2018-05-22T10:59:41 Z BThero Circle selection (APIO18_circle_selection) C++17
0 / 100
429 ms 38532 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) {
        for (int i = 0; i < 2; ++i) {
            int nv = v + v + i;

            if (!col[nv]) {
                col[nv] = 1;
                t[nv] = min(t[nv], 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 << 3); ++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:126:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
circle_selection.cpp:129: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 7448 KB Output is correct
3 Incorrect 8 ms 7472 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 429 ms 38456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 38456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 399 ms 38532 KB Execution killed with signal 11 (could be triggered by violating memory limits)
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 7448 KB Output is correct
3 Incorrect 8 ms 7472 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 7448 KB Output is correct
3 Incorrect 8 ms 7472 KB Output isn't correct
4 Halted 0 ms 0 KB -