Submission #1092607

# Submission time Handle Problem Language Result Execution time Memory
1092607 2024-09-24T14:52:19 Z damoon Pyramid Base (IOI08_pyramid_base) C++14
63 / 100
5000 ms 173908 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long

typedef pair<int,int> pii;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
#define f first
#define s second

#define all(x) x.begin(),x.end()
#define unicorn(x) x.resize(unique(x.begin(),x.end())-x.begin())

#define pb(x) push_back(x);
#define pp() pop_back();

#define lc (id<<1)+0
#define rc (id<<1)+1

const int LC = 1e6+2, L = 4e5+2;
const ll inf = 1e10;
int n,m,p,b;

vector<ppi> add[LC],er[LC];

random_device device;
default_random_engine rng(device());
#define randt(a,b) uniform_int_distribution<int64_t>(a,b)(rng)

struct node{
    ll lazy, mn;
    node(){
        lazy = mn = 0;
    }
}t[LC*6];
inline void spread(int id){
    t[lc].lazy += t[id].lazy;
    t[rc].lazy += t[id].lazy;
    t[id].mn += t[id].lazy;
    t[id].lazy = 0;
}
inline void update(int id,int l,int r,int l2,int r2,ll x){
    spread(id);
    if(l==l2 and r==r2){
        t[id].lazy += x;
        return;
    }
    int mid = (l2+r2)>>1;
    if(l<mid)
        update(lc,l,min(r,mid),l2,mid,x);
    if(r>mid)
        update(rc,max(l,mid),r,mid,r2,x);
    spread(lc);
    spread(rc);
    t[id].mn = min(t[lc].mn, t[rc].mn);
}

inline ll get(int id,int l,int r,int l2,int r2){
    spread(id);
    if(l==l2 and r==r2){
        return t[id].mn;
    }
    int mid = (l2+r2)>>1;
    ll ans = inf;
    if(l<mid)
        ans = min(ans, get(lc,l,min(r,mid),l2,mid));
    if(r>mid)
        ans = min(ans, get(rc,max(l,mid),r,mid,r2));
    return ans;
}

int main(){
    //ofstream cout ("out.txt");
    //ifstream cin ("in.txt");

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    scanf("%d %d",&n,&m);
    scanf("%d",&b);
    scanf("%d",&p);
    for(int i=0;i<p;i++){
        int x1,y1,x2,y2,pr;
        scanf("%d %d %d %d %d",&x1,&y1,&x2,&y2,&pr);
        ppi x = ppi(pii(y1,y2),pr);
        add[x1].pb(x);
        er[x2].pb(x);
    }

    int l=0,r=1e6+1;
    while(r-l>1){
        int mid = (l+r)>>1;
        if(mid > n or mid > m){
            r = mid;
            continue;
        }
        for(int i=1;i<LC*6;i++){
            t[i].lazy = t[i].mn = 0;
        }
        update(1,1,mid,1,m+1,inf);
        ll ans = inf;
        for(int i=1;i<=n;i++){
            if(i>mid){
                ans = min(ans,t[1].mn);
            }
            for(auto j:add[i]){
                update(1,max(j.f.f,mid),min(j.f.s+mid,m+1),1,m+1,j.s);
            }

            for(auto j:er[max(i-mid,0)]){
                update(1,max(j.f.f,mid),min(j.f.s+mid,m+1),1,m+1,-j.s);
            }

            if(i>mid){
                ans = min(ans,t[1].mn);
            }
        }
        if(ans <= b)
            l = mid;
        else
            r = mid;
    }
    cout<<l;
}

Compilation message

pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:81:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
pyramid_base.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |     scanf("%d",&b);
      |     ~~~~~^~~~~~~~~
pyramid_base.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |     scanf("%d",&p);
      |     ~~~~~^~~~~~~~~
pyramid_base.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         scanf("%d %d %d %d %d",&x1,&y1,&x2,&y2,&pr);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 79 ms 141272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 141136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 141136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 141392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 141192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 216 ms 141396 KB Output is correct
2 Correct 232 ms 141392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 141564 KB Output is correct
2 Correct 210 ms 141392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 141472 KB Output is correct
2 Correct 170 ms 141648 KB Output is correct
3 Correct 161 ms 141652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 315 ms 142416 KB Output is correct
2 Correct 382 ms 142416 KB Output is correct
3 Correct 325 ms 142416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 490 ms 143188 KB Output is correct
2 Correct 115 ms 142932 KB Output is correct
3 Incorrect 161 ms 142428 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 643 ms 143608 KB Output is correct
2 Correct 813 ms 143188 KB Output is correct
3 Correct 397 ms 143664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 535 ms 143952 KB Output is correct
2 Correct 1101 ms 143936 KB Output is correct
3 Correct 1025 ms 143696 KB Output is correct
4 Correct 1036 ms 143696 KB Output is correct
5 Correct 1044 ms 143736 KB Output is correct
6 Correct 412 ms 143956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5045 ms 158288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5069 ms 166272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5018 ms 173908 KB Time limit exceeded
2 Halted 0 ms 0 KB -