Submission #940871

# Submission time Handle Problem Language Result Execution time Memory
940871 2024-03-07T21:11:26 Z codefox Sails (IOI07_sails) C++14
5 / 100
201 ms 65536 KB
#include<bits/stdc++.h> 

using namespace std;

int N = 1<<20;
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]);
}

int search(int curr, int l, int r, int rr, int b, int p)
{
    if (bmin[curr]+p >= b || l >= rr) 
    {
        bpro[curr]+=p;
        bmin[curr]+=p;
        return 0;
    }
    if (l+1 == r) 
    {
        bpro[curr]+=p;
        bmin[curr]+=p;
        return l;
    }

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

    int m = (l+r)/2;
    int mx = search(curr*2+1, m, r, rr, b, p);
    if (mx == 0) mx = search(curr*2, l, m, rr, b, p);
    bmin[curr] = min(bmin[curr*2], bmin[curr*2+1]);
    return mx;    
}

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

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

    int left = 0;

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

    int upper = 1e6;

    for (int i = 1e6; i > 0; i--)
    {
        upper = min(upper, i);
        sort(height[i].begin(), height[i].end(), greater<int>());
        for (int ele:height[i])
        {
            int b = ceil(left/(double)upper);
            do
            {    
                int uh = bmin[upper+N];
                int curr = upper+N;
                while (curr>1)
                {
                    curr/=2;
                    uh+=bpro[curr];
                }
                if (uh >= b) 
                {
                    upper--;
                    left -= uh;
                }
                else break;
            }
            while (true);

            //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);
        }
        long long h = bmin[i+N];
        int curr = i+N;
        while (curr>1)
        {
            curr/=2;
            h+=bpro[curr];
        }
        if (h) sol += (h*(h-1))/2;
        if (upper == i) left -= h;
    }
    cout << sol << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 40284 KB Output is correct
2 Correct 29 ms 40284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 40284 KB Output is correct
2 Incorrect 28 ms 40284 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 40284 KB Output is correct
2 Incorrect 24 ms 40284 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 40280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 40280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 40536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 41560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 41820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 189 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 198 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 201 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -