답안 #940879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940879 2024-03-07T21:48:06 Z codefox Sails (IOI07_sails) C++14
5 / 100
83 ms 9556 KB
#include<bits/stdc++.h> 

using namespace std;

#define int long long

int N = 1<<17;
vector<int> bpro(2*N, 0);
vector<int> bmin(2*N, 0);

void update(int curr, int l, int r, int ll, int rr, int p)
{
    if (l >= rr || r <= ll) 
    {
        bpro[curr]+=p;
        bmin[curr]+=p;
        return;
    }
    if (l >= ll && r <= rr)
    {
        bpro[curr]+=p+1;
        bmin[curr]+=p+1;
        return;
    }

    p += bpro[curr];
    bpro[curr] = 0;

    int m = (l+r)/2;
    update(curr*2, l, m, ll, rr, p);
    update(curr*2+1, m, r, ll, rr, p);
    bmin[curr] = min(bmin[curr*2], bmin[curr*2+1]);
}

int32_t main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    vector<vector<int>> height(1e5+1);

    int left = 0;
    int sol = 0;
    int upper = 1e5;

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        height[a].push_back(b);
        left += b;
    }

    for (int i = 1e5; i > 0; i--)
    {
        sort(height[i].begin(), height[i].end(), greater<int>());
        for (int ele:height[i])
        {
            int uh, b;
            do
            {    
                b = left/upper +1;
                int ui = left%upper;
                uh = bmin[upper+N-ui];
                int curr = upper+N-ui;
                while (curr>1)
                {
                    curr/=2;
                    uh+=bpro[curr];
                }
                int c = upper+N;
                int hc = bmin[c];
                while(c>1)
                {
                    c/=2;
                    hc+=bpro[c];
                }
                if (hc >=b || uh >= b-1)
                {
                    left -= hc;
                    upper--;
                }
            }
            while (uh >=b-1);

            //int s = search(1, 0, N, i+1, b, 0)+1;
            //cout << bmin[N+s-1] << " " << s-ele << " " << s << endl;
            update(1, 0, N, upper-ele+1, upper+1, 0);
        }
        int h = bmin[i+N];
        int curr = i+N;
        while (curr>1)
        {
            curr/=2;
            h+=bpro[curr];
        }
        sol += (h*(h-1))/2;
        if (upper == i) 
        {
            left -= h;
            upper--;
        }
        //if (i <10) cout << h << endl;
    }
    cout << sol << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6748 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6748 KB Output is correct
2 Incorrect 3 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6748 KB Output is correct
2 Incorrect 3 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 6956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 7004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 8088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 8528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 9556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 83 ms 9552 KB Output isn't correct
2 Halted 0 ms 0 KB -