Submission #307704

# Submission time Handle Problem Language Result Execution time Memory
307704 2020-09-29T07:09:23 Z ansol4328 Pyramid Base (IOI08_pyramid_base) C++14
49 / 100
5000 ms 43684 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF=1e18;

struct SegTree{
    vector<ll> tree, lazy;
    int base;
    SegTree(int a){
        base=1;
        while(base<a) base<<=1;
        tree.resize(base*2+2);
        lazy.resize(base*2+2);
        for(int i=base+a ; i<base*2 ; i++) tree[i]=INF;
        for(int i=base-1 ; i>=1 ; i--) tree[i]=min(tree[i*2],tree[i*2+1]);
        base--;
    }
    void propagate(int ns, int nf, int num){
        if(lazy[num]!=0){
            if(ns<nf){
                lazy[num*2]+=lazy[num];
                lazy[num*2+1]+=lazy[num];
            }
            tree[num]+=lazy[num];
            lazy[num]=0;
        }
    }
    ll query(int st, int fn, int ns=1, int nf=-1, int num=1){
        if(nf==-1) nf=base+1;
        propagate(ns,nf,num);
        if(ns>fn || nf<st) return INF;
        if(st<=ns && nf<=fn) return tree[num];
        int mid=(ns+nf)>>1;
        return min(query(st,fn,ns,mid,num*2),query(st,fn,mid+1,nf,num*2+1));
    }
    void add_value(ll val, int st, int fn, int ns=1, int nf=-1, int num=1){
        if(nf==-1) nf=base+1;
        propagate(ns,nf,num);
        if(ns>fn || nf<st) return;
        if(st<=ns && nf<=fn){
            lazy[num]+=val;
            propagate(ns,nf,num);
            return;
        }
        int mid=(ns+nf)>>1;
        add_value(val,st,fn,ns,mid,num*2);
        add_value(val,st,fn,mid+1,nf,num*2+1);
        tree[num]=min(tree[num*2],tree[num*2+1]);
    }
};

struct A{
    int x1, y1, x2, y2, c;
    A(){}
    A(int t1, int t2, int t3, int t4, int t5) : x1(t1), y1(t2), x2(t3), y2(t4), c(t5) {}
};

bool cmp(const A &lhs, const A &rhs){
    return lhs.y1==rhs.y1 ? lhs.y2<rhs.y2 : lhs.y1<rhs.y1;
}

int m, n, p;
ll b;
A ob[400005];

bool pos(int w)
{
    SegTree T(m-w+1);
    priority_queue<P,vector<P>,greater<P> > PQ;
    int idx=1, st, fn, k;
    for(int sy=1, fy=w ; fy<=n ; sy++, fy++){
        while(!PQ.empty() && PQ.top().first<sy){
            k=PQ.top().second; PQ.pop();
            st=max(1,ob[k].x1-w+1);
            fn=min(m-w+1,ob[k].x2);
            T.add_value(-ob[k].c,st,fn);
        }
        while(idx<=p && ob[idx].y1>=sy && ob[idx].y1<=fy){
            st=max(1,ob[idx].x1-w+1);
            fn=min(m-w+1,ob[idx].x2);
            T.add_value(ob[idx].c,st,fn);
            PQ.push(P(ob[idx].y2,idx));
            idx++;
        }
        if(T.query(1,m-w+1)<=b) return true;
    }
    return false;
}

int main()
{
    scanf("%d %d",&m,&n);
    scanf("%lld",&b);
    scanf("%d",&p);
    for(int i=1 ; i<=p ; i++){
        scanf("%d %d %d %d %d",&ob[i].x1,&ob[i].y1,&ob[i].x2,&ob[i].y2,&ob[i].c);
    }
    sort(ob+1,ob+1+p,cmp);
    int st=1, fn=min(m,n), mid, ans=0;
    while(st<=fn){
        mid=(st+fn)>>1;
        if(pos(mid)) st=mid+1, ans=mid;
        else fn=mid-1;
    }
    printf("%d",ans);
    return 0;
}

Compilation message

pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:94:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   94 |     scanf("%d %d",&m,&n);
      |     ~~~~~^~~~~~~~~~~~~~~
pyramid_base.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   95 |     scanf("%lld",&b);
      |     ~~~~~^~~~~~~~~~~
pyramid_base.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   96 |     scanf("%d",&p);
      |     ~~~~~^~~~~~~~~
pyramid_base.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   98 |         scanf("%d %d %d %d %d",&ob[i].x1,&ob[i].y1,&ob[i].x2,&ob[i].y2,&ob[i].c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 283 ms 4592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 830 ms 16768 KB Output is correct
2 Correct 4677 ms 33488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4398 ms 33556 KB Output is correct
2 Correct 1518 ms 16932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 896 KB Output is correct
2 Correct 64 ms 1208 KB Output is correct
3 Correct 89 ms 1336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 358 ms 5368 KB Output is correct
2 Correct 835 ms 5468 KB Output is correct
3 Correct 733 ms 5356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1194 ms 18268 KB Output is correct
2 Correct 437 ms 34416 KB Output is correct
3 Correct 56 ms 1400 KB Output is correct
4 Execution timed out 5053 ms 34812 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2567 ms 34640 KB Output is correct
2 Execution timed out 5100 ms 34724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1786 ms 18884 KB Output is correct
2 Execution timed out 5013 ms 35260 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5095 ms 39260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5068 ms 41724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5059 ms 43684 KB Time limit exceeded
2 Halted 0 ms 0 KB -