Submission #483086

# Submission time Handle Problem Language Result Execution time Memory
483086 2021-10-27T16:23:00 Z blue Sails (IOI07_sails) C++17
25 / 100
47 ms 27400 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;

const long long INF = 1'000'000'000'000'000'000LL;

long long ans = 0;

struct segtree
{
    int l;
    int r;
    pair<long long, int> v;
    long long lp = 0;

    segtree* left = NULL;
    segtree* right = NULL;

    segtree()
    {
        ;
    }

    segtree(int L, int R)
    {
        l = L;
        r = R;
        v = make_pair(0LL, l);

        if(l == r) return;

        int m = (l+r)/2;
        left = new segtree(l, m);
        right = new segtree(m+1, r);
    }

    void add(int L, int R, long long V)
    {
        if(R < l || r < L) return;
        else if(L <= l && r <= R)
        {
            v.first += V;
            lp += V;
        }
        else
        {
            left->add(L, R, V);
            right->add(L, R, V);
            v = min(left->v, right->v);
            v.first += lp;
        }
    }

    pair<long long, int> rangemin(int L, int R)
    {
        if(R < l || r < L) return make_pair(INF, -1);
        else if(L <= l && r <= R) return v;
        else
        {
            pair<long long, int> ans = min(left->rangemin(L, R), right->rangemin(L, R));
            ans.first += lp;
            return ans;
        }
    }

    void dfs(long long k)
    {
        k += lp;
        if(l == r) ans += k*(k-1)/2;
        else
        {
            left->dfs(k);
            right->dfs(k);
        }
    }
};

const int mx = 100'000;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;

    vector< pair<int, int> > S(N);
    for(int i = 0; i < N; i++) cin >> S[i].first >> S[i].second;
    sort(S.begin(), S.end());

    segtree ST(1, mx);
    for(int i = 0; i < N; i++)
    {
        int occ_lo = 0;
        int occ_hi = S[i].first + 1;
        // cerr << "\n\n\n";
        // cerr << "i = " << i << '\n';
        // cerr << S[i].first << ' ' << S[i].second << '\n';
        int ct = 0;
        while(S[i].second > 0)
        {
            pair<long long, int> mn = ST.rangemin(occ_lo+1, occ_hi-1);
            assert(mn.second == 1 || ST.rangemin(mn.second-1, mn.second-1) > ST.rangemin(mn.second, mn.second));

            int loc = mn.second;
            int upd = min(S[i].second, occ_hi - loc);
            S[i].second -= upd;
            ST.add(loc, loc + upd - 1, +1);

            if(loc == occ_lo+1)
                occ_lo += upd;
            if(loc+upd-1 == occ_hi - 1)
                occ_hi -= upd;

            // cerr << "adding +1 to " << loc << ' ' << loc + upd - 1 << '\n';
            ct++;
        }
        assert(ct <= 5);
    }
    // cerr << "updating done\n";

    ST.dfs(0);

    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12760 KB Output is correct
2 Correct 10 ms 12748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12828 KB Output is correct
2 Correct 10 ms 12748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12836 KB Output is correct
2 Correct 10 ms 12736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 25828 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 25808 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 21 ms 25956 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 26252 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 29 ms 26564 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 47 ms 27076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 40 ms 27268 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 27400 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -