답안 #483073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483073 2021-10-27T16:04:56 Z blue Sails (IOI07_sails) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
using namespace std;

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

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;
        }
    }
};

const int mx = 100'000;

int main()
{
    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++)
    {
        while(S[i].second > 0)
        {
            pair<long long, int> mn = ST.rangemin(1, S[i].first);
            int upd = min(S[i].second, S[i].first - mn.second + 1);
            S[i].second -= upd;
            ST.add(mn.second, mn.second + upd - 1, +1);
        }
    }

    long long ans = 1;
    for(int h = 1; h <= mx; h++)
    {
        pair<long long, int> p = ST.rangemin(h, h);
        ans += (p.first * (p.first - 1))/2;
    }

    cout << ans << '\n';
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:74:5: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   74 |     sort(S.begin(), S.end());
      |     ^~~~
      |     qsort