Submission #114280

# Submission time Handle Problem Language Result Execution time Memory
114280 2019-05-31T16:46:31 Z popovicirobert Sails (IOI07_sails) C++14
30 / 100
1000 ms 7076 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MAXH = (int) 1e5;

struct SegTree {

    vector < pair <int, int> > aint;
    int n;

    inline void init(int _n) {
        n = _n;
        aint.resize(4 * n + 1);
    }

    inline void combine(pair <int, int> &a, pair <int, int> b) {
        if(a.first > b.first)
            a = b;
    }

    void update(int nod, int left, int right, int pos, int val) {
        if(left == right) {
            aint[nod] = {val, left};
        }
        else {
            int mid = (left + right) / 2;

            if(pos <= mid) update(2 * nod, left, mid, pos, val);
            else update(2 * nod + 1, mid + 1, right, pos, val);

            aint[nod] = {MAXH + 1, 0};

            combine(aint[nod], aint[2 * nod]);
            combine(aint[nod], aint[2 * nod + 1]);
        }
    }

    pair <int, int> query(int nod, int left, int right, int l, int r) {
        if(l <= left && right <= r) {
            return aint[nod];
        }
        else {
            int mid = (left + right) / 2;
            pair <int, int> ans = {MAXH + 1, 0};

            if(l <= mid) combine(ans, query(2 * nod, left, mid, l, r));
            if(mid < r) combine(ans, query(2 * nod + 1, mid + 1, right, l, r));

            return ans;
        }
    }

};


int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;

    vector <int> h(n + 1), k(n + 1), ord(n + 1);
    for(i = 1; i <= n; i++) {
        cin >> h[i] >> k[i];
        ord[i] = i;
    }

    sort(next(ord.begin()), ord.end(), [&](const int &a, const int &b) {

            return h[a] < h[b];

         });

    SegTree st; st.init(MAXH);

    for(i = 1; i <= MAXH; i++) {
        st.update(1, 1, MAXH, i, 0);
    }

    for(i = 1; i <= n; i++) {

        vector < pair <int, int> > aux;

        while(k[ord[i]]--) {
            auto cur = st.query(1, 1, MAXH, 1, h[ord[i]]);
            aux.push_back({cur.first + 1, cur.second});
            st.update(1, 1, MAXH, cur.second, MAXH + 1);
        }

        for(auto it : aux) {
            st.update(1, 1, MAXH, it.second, it.first);
        }
    }

    ll ans = 0;
    for(i = 1; i <= MAXH; i++) {
        int cur = st.query(1, 1, MAXH, i, i).first;
        ans += 1LL * cur * (cur - 1) / 2;
    }

    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3456 KB Output is correct
2 Correct 23 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3456 KB Output is correct
2 Correct 22 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3456 KB Output is correct
2 Correct 25 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3456 KB Output is correct
2 Correct 66 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 3824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 3924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 4344 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 4764 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 7076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 5508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 5996 KB Time limit exceeded
2 Halted 0 ms 0 KB -