Submission #970005

# Submission time Handle Problem Language Result Execution time Memory
970005 2024-04-26T05:30:21 Z steveonalex Circle selection (APIO18_circle_selection) C++17
12 / 100
299 ms 32828 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 3e5 + 69;
const int INF = 2e9 + 69;
int ans[N];

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

struct SegmentTreeMax{
    int n;
    vector<pair<int, int>> a;

    SegmentTreeMax(int _n){
        n = _n;
        a.resize(n * 2 + 2, {-INF, -INF});
        for(int i = 1; i<=n; ++i) a[i+n] = {0, i};
        for(int i = n; i>=1; --i) a[i] = max(a[i * 2], a[i * 2 + 1]);
    }

    void update(int i, int v){
        i += n; a[i].first = v;
        while(i > 1){
            i >>= 1;
            a[i] = max(a[i * 2], a[i * 2 + 1]);
        }
    }

    pair<int, int> get(int l, int r){
        l += n; r += n + 1;
        pair<int, int> ans = {-INF, -INF};
        while(l < r){
            if (l & 1) maximize(ans, a[l++]);
            if (r & 1) maximize(ans, a[--r]);
            l >>= 1; r >>= 1;
        }
        return ans;
    }
};


int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    int n; cin >> n;
    vector<array<int, 4>> a(n+1);
    for(int i = 1; i<=n; ++i) {
        for(int j = 0; j < 3; ++j) cin >> a[i][j];
        a[i][3] = i;
    }

    for(int i = 1; i<=n; ++i) if (a[i][1] != 0) exit(1);

    vector<array<int, 4>> b = a;
    sort(1 + ALL(b), [](array<int, 4> x, array<int, 4> y){
        if (x[2] != y[2]) return x[2] > y[2];
        return x[3] < y[3];
    });

    vector<array<int, 4>> c = a;
    sort(1 + ALL(c), [](array<int, 4> x, array<int, 4> y){
        return x[0] < y[0];
    });

    vector<int> pos(n+1);
    for(int i = 1; i<=n; ++i) pos[c[i][3]] = i;

    SegmentTreeMax st_left(n), st_right(n);
    for(int i = 1; i<=n; ++i) {
        st_left.update(i, c[i][0] + c[i][2]);
        st_right.update(i, c[i][2] - c[i][0]);
    }

    for(int i = 1; i<=n; ++i){
        if (ans[b[i][3]] > 0) continue;
        int x = b[i][0], r = b[i][2], poo = b[i][3];
        ans[poo] = poo;

        int j = pos[poo];
        st_left.update(j, -INF); st_right.update(j, -INF);

        while(true){
            pair<int, int> t = st_left.get(1, j);
            if (t.first < x - r) break;
            int k = c[t.second][3];
            st_left.update(t.second, -INF);
            if (ans[k] == 0) ans[k] = poo;
        }
        while(true){
            pair<int, int> t = st_right.get(j, n);
            if (t.first < -(x+r)) break;
            int k = c[t.second][3];
            st_right.update(t.second, -INF);
            if (ans[k] == 0) ans[k] = poo;
        }
    }

    for(int i = 1; i<=n; ++i) cout << ans[i] << " ";
        cout << "\n";
    

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 263 ms 31912 KB Output is correct
2 Correct 247 ms 31980 KB Output is correct
3 Correct 243 ms 31560 KB Output is correct
4 Correct 241 ms 32036 KB Output is correct
5 Correct 240 ms 30544 KB Output is correct
6 Correct 299 ms 32748 KB Output is correct
7 Correct 248 ms 32792 KB Output is correct
8 Correct 251 ms 32828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 70 ms 9152 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -