Submission #993679

# Submission time Handle Problem Language Result Execution time Memory
993679 2024-06-06T10:05:02 Z codefox Pyramid Base (IOI08_pyramid_base) C++14
70 / 100
5000 ms 106296 KB
#include<bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define arr array<int, 5>

int N = 1<<20;

vector<int> bmin(2*N, 0);
vector<int> badd(2*N, 0);

void update(int curr, int l, int r, int a, int b, int add, int dd)
{
    if (r<=a || l>=b) 
    {
        bmin[curr] += add;
        badd[curr] += add;
        return;
    }
    if (a<=l && r<=b)
    {
        add+=dd;
        bmin[curr] += add;
        badd[curr] += add;
        return;
    }
    int m = (l+r)/2;
    add+=badd[curr];
    badd[curr] = 0;
    update(curr*2, l, m, a, b, add, dd);
    update(curr*2+1, m, r, a, b, add, dd);
    bmin[curr] = min(bmin[curr*2], bmin[curr*2+1]);
}

int finde(int pos)
{
    int curr = 1;
    int sol = 2*1e9+1;
    int add = 0;
    for (int i = 19; i >= 0; i--)
    {
        add += badd[curr];
        curr*=2;
        if (pos < (1<<i)) continue;
        pos -= 1<<i;
        sol = min(sol, bmin[curr]+add);
        curr++;
    }
    return sol;
}

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

    int x, y;
    cin >> x >> y;
    int b, n;
    cin >> b >> n;

    vector<arr> ele(n);
    for (int i= 0; i < n; i++)
    {
        int x1, y1, x2, y2, c;
        cin >> x1 >> y1 >> x2 >> y2 >> c;
        x1--; y1--; x2--; y2--;
        ele[i] = {x1, y1, x2, y2, c};
    }

    int sum = 0;
    for (int i = 20; i >= 0; i--)
    {
        sum += 1<<i;
        vector<vector<arr>> begin(1e6);
        vector<vector<arr>> ende(1e6);
        bmin.assign(2*N, 0);
        badd.assign(2*N, 0);
        for (int j = 0; j < n; j++)
        {
            begin[max(0, ele[j][0]-sum+1)].push_back({max(0, ele[j][1]-sum+1), ele[j][3], ele[j][4]});
            ende[ele[j][2]].push_back({max(0, ele[j][1]-sum+1), ele[j][3], ele[j][4]});
        }
        int mn = 2*1e9+1;
        for (int j = 0; j < x-sum+1; j++)
        {
            for (arr ele2:begin[j]) update(1, 0, N, ele2[0], ele2[1]+1, 0, ele2[2]);
            mn = min(mn, finde(y-sum+1));
            for (arr ele2:ende[j]) update(1, 0, N, ele2[0], ele2[1]+1, 0, -ele2[2]);
        }
        if (mn > b) sum -= 1<<i;
    }
    cout << sum;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 234 ms 63844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 63836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 63956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 63872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 262 ms 63880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 343 ms 64176 KB Output is correct
2 Correct 590 ms 63932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 598 ms 64088 KB Output is correct
2 Correct 341 ms 63836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 400 ms 64572 KB Output is correct
2 Correct 326 ms 64520 KB Output is correct
3 Correct 233 ms 64312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 435 ms 65476 KB Output is correct
2 Correct 476 ms 65520 KB Output is correct
3 Correct 437 ms 65508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 66144 KB Output is correct
2 Correct 840 ms 66092 KB Output is correct
3 Correct 268 ms 65932 KB Output is correct
4 Correct 1083 ms 66156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 952 ms 66696 KB Output is correct
2 Correct 1276 ms 66640 KB Output is correct
3 Correct 630 ms 67072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 794 ms 67424 KB Output is correct
2 Correct 1452 ms 67128 KB Output is correct
3 Correct 1465 ms 67136 KB Output is correct
4 Correct 1429 ms 67084 KB Output is correct
5 Correct 1503 ms 67232 KB Output is correct
6 Correct 557 ms 67236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5102 ms 85504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5027 ms 96316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5070 ms 106296 KB Time limit exceeded
2 Halted 0 ms 0 KB -