Submission #588196

# Submission time Handle Problem Language Result Execution time Memory
588196 2022-07-02T18:53:19 Z Bench0310 Pyramid Base (IOI08_pyramid_base) C++17
5 / 100
5000 ms 106576 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int N=1000001;
ll t[2000002];
ll d[1000001];
int h;

void apply(int p,ll val)
{
    t[p]+=val;
    if(p<N) d[p]+=val;
}

void build(int p)
{
    while(p>1){p/=2; t[p]=min(t[2*p],t[2*p+1])+d[p];}
}

void push(int p)
{
    for(int s=h;s>0;s--)
    {
        int i=(p>>s);
        if(d[i]!=0)
        {
            apply(2*i,d[i]);
            apply(2*i+1,d[i]);
            d[i]=0;
        }
    }
}

void update(int l,int r,ll val)
{
    l+=N; r+=(N+1);
    int l0=l,r0=r;
    for(;l<r;l/=2,r/=2)
    {
        if(l&1) apply(l++,val);
        if(r&1) apply(--r,val);
    }
    build(l0);
    build(r0-1);
}

ll query(int l,int r)
{
    l+=N; r+=(N+1);
    push(l);
    push(r-1);
    ll res=(1ll<<32);
    for(;l<r;l/=2,r/=2)
    {
        if(l&1) res=min(res,t[l++]);
        if(r&1) res=min(res,t[--r]);
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> m >> n;
    int b,p;
    cin >> b >> p;
    vector<array<int,5>> obstacles(p);
    for(auto &[x1,y1,x2,y2,c]:obstacles) cin >> x1 >> y1 >> x2 >> y2 >> c;
    int l=0,r=min(n,m)+1;
    vector<array<int,3>> v[m+2];
    while(l<r-1)
    {
        int len=(l+r)/2;
        bool ok=0;
        int limm=m-len+1;
        int limn=n-len+1;
        N=limn;
        h=32-__builtin_clz(N);
        auto add=[&](int x1,int y1,int x2,int y2,int c)
        {
            v[x1].push_back({y1,y2,c});
            v[x2+1].push_back({y1,y2,-c});
        };
        for(auto [x1,y1,x2,y2,c]:obstacles) add(max(1,x1-len+1),max(1,y1-len+1),min(x2,limm),min(y2,limn),c);
        for(int x=1;x<=limm+1;x++)
        {
            for(auto [y1,y2,c]:v[x]) update(y1,y2,c);
            if(x<=limm) ok|=(query(1,limn)<=b);
            v[x].clear();
        }
        if(ok) l=len;
        else r=len;
    }
    cout << l << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 5232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 315 ms 31668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1248 ms 46212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 179 ms 8188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 860 ms 43344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1204 ms 51856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 805 ms 46148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4514 ms 90280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5072 ms 101860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5058 ms 106576 KB Time limit exceeded
2 Halted 0 ms 0 KB -