Submission #472677

#TimeUsernameProblemLanguageResultExecution timeMemory
472677HaidaraWall (IOI14_wall)C++17
0 / 100
279 ms8016 KiB
/** * * * * * * * * * * * * * * **\ * * * Author: Haidara Nassour * * Coded in: 2021\09\12 HH:MM:SS * * Lang: C++ * * * \** * * * * * * * * * * * * * * **/ #include<bits/stdc++.h> #include<wall.h> #define rep(i,x,n) for(int i=x;i<n;i++) #define FOR(i,n) rep(i,0,n) using namespace std; const int maxn=200200; int n; struct node { int mx=0,mn=0,lazy=-1; } st[maxn*4]; bool add=0; int ul,ur,val; void pull(int inx,int l,int r) { if(st[inx].lazy==-1) return ; if(add) { st[inx].mn=max(st[inx].lazy,st[inx].mn); st[inx].mx=max(st[inx].mn,st[inx].mx); if(l!=r) { st[inx*2].lazy=max(st[inx].lazy,st[inx*2].lazy); st[inx*2+1].lazy=max(st[inx].lazy,st[inx*2+1].lazy); } } else { st[inx].mx=min(st[inx].mx,st[inx].lazy); st[inx].mn=min(st[inx].mn,st[inx].mx); if(l!=r) { st[inx*2].lazy=min(st[inx].lazy,st[inx*2].lazy); st[inx*2+1].lazy=min(st[inx].lazy,st[inx*2+1].lazy); } } st[inx].lazy=-1; } int check(int inx,int type) { int mintall=st[inx].mn,maxtall=st[inx].mx; if(st[inx].lazy!=-1) { if(add) { mintall=max(st[inx].lazy,st[inx].mn); maxtall=max(st[inx].mn,st[inx].mx); } else { maxtall=min(st[inx].mx,st[inx].lazy); mintall=min(st[inx].mn,st[inx].mx); } } if(type==1) return mintall; return maxtall; } void pu(int inx) { /// 1-> min /// 2-> max st[inx].mn=min(check(inx*2,1),check(inx*2+1,1)); st[inx].mx=max(check(inx*2,2),check(inx*2+1,2)); } void update(int l=1,int r=n,int inx=1) { pull(inx,l,r); if(ul<=l&&r<=ur) { st[inx].lazy=val; pull(inx,l,r); return ; } if(l>ur||ul>r) return ; int mid=l+(r-l)/2; update(l,mid,inx*2); update(mid+1,r,inx*2+1); pu(inx); } int query(int pos,int l=1,int r=n,int inx=1) { pull(inx,l,r); if(l==r) { if(st[inx].mn==st[inx].mx) return st[inx].mn; return -500; } int mid=l+(r-l)/2; if(pos<=mid) return query(pos,l,mid,inx*2); return query(pos,mid+1,r,inx*2+1); } void buildWall(int sz, int k, int op[], int left[], int right[],int height[], int finalHeight[]) { n=sz; FOR(i,k) { val=height[i]; ul=left[i]+1; ur=right[i]+1; if(op[i]==1) add=1; else add=0; update(); } FOR(i,n) finalHeight[i]=query(i+1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...