Submission #472679

#TimeUsernameProblemLanguageResultExecution timeMemory
472679HaidaraWall (IOI14_wall)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include"wall.h" #define FOR(i,n) for(int i=0;i<n;i++) using namespace std; const int maxn=2000200; int n; struct node { int mx=0,mn=0,lazy=-1; } st[maxn*2+2]; 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); }

Compilation message (stderr)

Compilation timeout while compiling wall