Submission #1019302

# Submission time Handle Problem Language Result Execution time Memory
1019302 2024-07-10T17:09:12 Z ttamx Pyramid Base (IOI08_pyramid_base) C++17
90 / 100
5000 ms 84200 KB
#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>

using namespace std;

const int N=1e6+5;
const int INF=INT_MAX/2;

int n,m,b,p;
vector<tuple<int,int,int>> add[N],del[N];

struct SegTree{
    int n,log;
    int t[2*N],lz[2*N];
    void init(int _n){
        n=_n;
        log=32-__builtin_clz(n);
    }
    void apply(int i,int v){
        t[i]+=v,lz[i]+=v;
    }
    void push(int i){
        apply(i<<1,lz[i]);
        apply(i<<1|1,lz[i]);
        lz[i]=0;
    }
    void pull(int i){
        t[i]=min(t[i<<1],t[i<<1|1]);
    }
    void build(){
        for(int i=1;i<2*n;i++)t[i]=lz[i]=0;
    }
    void update(int l,int r,int v){
        if(l>r)return;
        l+=n-1,r+=n;
        for(int i=log;i>=1;i--){
            if(((l>>i)<<i)!=l)push(l>>i);
            if(((r>>i)<<i)!=r)push((r-1)>>i);
        }
        for(int l2=l,r2=r;l2<r2;l2>>=1,r2>>=1){
            if(l2&1)apply(l2++,v);
            if(r2&1)apply(--r2,v);
        }
        for(int i=1;i<=log;i++){
            if(((l>>i)<<i)!=l)pull(l>>i);
            if(((r>>i)<<i)!=r)pull((r-1)>>i);
        }
    }
}seg;

bool check(int k){
    seg.build();
    seg.update(1,k-1,INF);
    for(int i=1;i<k;i++)for(auto [l,r,v]:add[i])seg.update(max(l,k),min(r+k-1,n),v);
    for(int i=k;i<=m;i++){
        for(auto [l,r,v]:add[i])seg.update(max(l,k),min(r+k-1,n),v);
        for(auto [l,r,v]:del[i-k])seg.update(max(l,k),min(r+k-1,n),-v);
        if(seg.t[1]<=b)return true;
    }
    return false;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> m >> n >> b >> p;
    for(int i=0;i<p;i++){
        int x1,y1,x2,y2,c;
        cin >> x1 >> y1 >> x2 >> y2 >> c;
        add[x1].emplace_back(y1,y2,c);
        del[x2].emplace_back(y1,y2,c);
    }
    seg.init(n);
    int l=0,r=min(n,m);
    while(l<r){
        int m=(l+r+1)/2;
        if(check(m))l=m;
        else r=m-1;
    }
    cout << l;
}
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 47320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 47444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 49040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 62984 KB Output is correct
2 Correct 129 ms 63112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 63072 KB Output is correct
2 Correct 104 ms 63120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 47808 KB Output is correct
2 Correct 51 ms 47812 KB Output is correct
3 Correct 49 ms 47688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 49876 KB Output is correct
2 Correct 161 ms 49840 KB Output is correct
3 Correct 148 ms 49744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 223 ms 64288 KB Output is correct
2 Correct 52 ms 48468 KB Output is correct
3 Correct 82 ms 63828 KB Output is correct
4 Correct 268 ms 64088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 339 ms 64600 KB Output is correct
2 Correct 506 ms 64432 KB Output is correct
3 Correct 207 ms 64340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 295 ms 64884 KB Output is correct
2 Correct 545 ms 64604 KB Output is correct
3 Correct 510 ms 64596 KB Output is correct
4 Correct 691 ms 64768 KB Output is correct
5 Correct 660 ms 64592 KB Output is correct
6 Correct 226 ms 64700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2312 ms 74476 KB Output is correct
2 Correct 455 ms 55120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3639 ms 79512 KB Output is correct
2 Correct 3507 ms 76736 KB Output is correct
3 Correct 1153 ms 71552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3975 ms 84200 KB Output is correct
2 Execution timed out 5064 ms 82368 KB Time limit exceeded
3 Halted 0 ms 0 KB -