Submission #365420

# Submission time Handle Problem Language Result Execution time Memory
365420 2021-02-11T15:58:57 Z valerikk Comparing Plants (IOI20_plants) C++17
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9 + 100;

struct SegTree {
    struct Data {
        int mn, pos;

        void apply(int x) {
            mn += x;
        }

        Data() : mn(INF), pos(-1) {}

        Data(int mn, int pos) : mn(mn), pos(pos) {} 
    };

    Data merge(const Data &l, const Data &r) {
        return l.mn <= r.mn ? l : r;
    }

    int sz;
    vector<Data> t;
    vector<int> mod;

    void apply(int i, int x) {
        t[i].apply(x);
        mod[i] += x;
    }


    void update(int i) {
        t[i] = merge(t[2 * i], t[2 * i + 1]);
    }

    void push(int i) {
        apply(2 * i, mod[i]);
        apply(2 * i + 1, mod[i]);
        mod[i] = 0;
    }

    void modify(int i, int l, int r, int ql, int qr, int x) {
        if (l >= qr || r <= ql)
            return;
        if (l >= ql && r <= qr) {
            apply(i, x);
            return;
        }
        push(i);
        int mid = (l + r) / 2;
        modify(2 * i, l, mid, ql, qr, x);
        modify(2 * i + 1, mid, r, ql, qr, x);
        update(i);
    }

    void replace_single(int i, int l, int r, int pos, int val) {
        if (r - l == 1) {
            t[i] = Data{val, pos};
            mod[i] = 0;
        } else {
            push(i);
            int mid = (l + r) / 2;
            if (pos < mid)
                replace_single(2 * i, l, mid, pos, val);
            else 
                replace_single(2 * i + 1, mid, r, pos, val);
            update(i);
        }
    }

    void replace_single(int pos, int val) {
        replace_single(1, 0, sz, pos, val);
    }

    void modify(int l, int r, int x) {
        modify(1, 0, sz, l, r, x);
    }

    int find_min() {
        return t[1].pos;
    }

    void build(int i, int l, int r, const vector<int> &a) {
        if (r - l == 1) {
            t[i] = {a[l], l};
        } else {
            int mid = (l + r) / 2;
            build(2 * i, l, mid, a);
            build(2 * i + 1, mid, r, a);
            update(i);
        }
    }

    SegTree() = default;

    SegTree(const vector<int> &a) {
        sz = a.size();
        t = vector<Data>(4 * sz);
        mod = vector<int>(4 * sz, 0);
        build(1, 0, sz, a);
    }
};

int k, n;
vector<int> r;
vector<int> h;

void build_h() {
    h = vector<int>(n, -1);
    SegTree st(r);
    for (int t = 0; t < n; t++) {
        int pos = st.find_min();
        h[pos] = t;
        st.replace_single(pos, INF);
        if (pos - k + 1 >= 0) 
            st.modify(pos - k + 1, pos, -1);
        else {
            st.modify(0, pos, -1);
            st.modify(n - (k - 1 - pos), n, -1);
        }
    }
}

void init(int k_, vector<int> r_) {
    n = r_.size();
    k = k_;
    r = r_;

    build_h();
}

int compare_plants(int x, int y) {
    return h[x] > h[y] ? 1 : -1;
}

#ifndef EVAL
void test() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> r(n);
    for (int i = 0; i < n; i++) 
        cin >> r[i];
    
    init(k, r);
  
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        cout << compare_plants(x, y) << "\n";
    }
}

int main() {
    freopen("D:/cp/oi/ioi/2020/input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    test();

    return 0;
}
#endif

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -