Submission #1356170

#TimeUsernameProblemLanguageResultExecution timeMemory
1356170opeleklanos사탕 분배 (IOI21_candies)C++20
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define ll long long

#define INFI (ll)1000000000000000000

struct segTree{
    ll l; ll r;
    segTree *lc, *rc;
    pair<ll, ll> mx;
    pair<ll, ll> mn;
    ll lazy;

    segTree(ll st){
        l = r = st;
        lc = rc = nullptr;
        mx = mn = {0, st};
        lazy = 0;
    }

    segTree(segTree * le, segTree * ri){
        lc = le; rc = ri;
        mx = max(lc->mx, rc->mx);
        mn = min(lc->mn, rc->mn);
        lazy = 0;
        l = le->l;
        r = ri->r;
    }
};

segTree * build (ll l, ll r){
    if(l == r) return new segTree(l);
    return new segTree(build(l, (l+r)/2), build((l+r)/2 + 1, r));
}

void update(ll l, ll r, ll x, segTree*st){

    st->mn.first += st->lazy;
    st->mx.first += st->lazy;
    if(st->l != st->r){
        st->lc->lazy += st->lazy;
        st->rc->lazy += st->lazy;
    }
    st->lazy = 0;

    if(st->l == st->r){
        st->mn.first += x;
        st->mx.first += x;
        st->lazy = 0;
        return;
    }
    if(st->l == l && st->r == r){
        st->lc->lazy += x;
        st->rc->lazy += x;
        st->mn.first += x;
        st->mx.first += x;
        st->lazy = 0;
        return;
    }
    ll mid = (st->l + st->r)/2;

    if(l<=mid) update(l, min(r, mid), x, st->lc);
    if(r>mid) update(max(mid+1, l), r, x, st->rc);

    st->mn = min(st->lc->mn, st->rc->mn);
    st->mx = max(st->lc->mx, st->rc->mx);
}

pair<ll, ll> query(ll md, ll l, ll r, segTree * st){
    st->mn.first += st->lazy;
    st->mx.first += st->lazy;
    if(st->l != st->r){
        st->lc->lazy += st->lazy;
        st->rc->lazy += st->lazy;
    }
    st->lazy = 0;

    if(st->l == st->r){
        if(md == 0) return st->mn;
        else return st->mx;
    }

    ll mid = (st->l + st->r)/2;

    if(md == 0){
        pair<ll, ll> ans = {INFI, INFI};
        if(l <= mid) ans = min(ans, query(md, l, min(r, mid), st->lc));
        if(r > mid) ans = min(ans, query(md, max(l, mid+1), r, st->rc));
        return ans;
    }

    //if(md == 1){
        pair<ll, ll> ans = {-INFI, -INFI};
        if(l <= mid) ans = max(ans, query(md, l, min(r, mid), st->lc));
        if(r > mid) ans = max(ans, query(md, max(l, mid+1), r, st->rc));
        return ans;
    //}
}

ll findMaxInd(ll c, segTree * st, pair<ll, ll> minR, pair<ll, ll> maxR){

    st->mn.first += st->lazy;
    st->mx.first += st->lazy;
    if(st->l != st->r){
        st->lc->lazy += st->lazy;
        st->rc->lazy += st->lazy;
    }
    st->lazy = 0;

    if(st->l == st->r){
        return st->l;
    }

    if(max(maxR, st->rc->mx).first - min(st->rc->mn, minR).first >= c){
        return findMaxInd(c, st->rc, minR, maxR);
    }
    return findMaxInd(c, st->lc, min(minR, st->rc->mn), max(maxR, st->rc->mx));
}

Compilation message (stderr)

/usr/bin/ld: /tmp/cc7o1Nv3.o: in function `main':
grader.cpp:(.text.startup+0x2fe): undefined reference to `distribute_candies(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status