이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct node{
node *l,*r;
int mx,mn;
void addtag(int t,int x){
if(t==1)mn=max(mn,x),mx=max(mx,mn);
else mx=min(mx,x),mn=min(mn,mx);
}
void push(){
if(!l)return;
l->addtag(1,mn);
l->addtag(2,mx);
r->addtag(1,mn);
r->addtag(2,mx);
mx=1e9,mn=-1e9;
}
node():l(0),r(0),mx(1e9),mn(-1e9){}
} *root;
int *ans;
#define mid ((l+r)>>1)
void build(node *now,int l,int r){
if(l==r){ return; }
build(now->l=new node(),l,mid);
build(now->r=new node(),mid+1,r);
}
void modify(node *now,int l,int r,int ml,int mr,int t,int x){
if(r<ml || mr<l)return;
now->push();
if(ml<=l&&r<=mr){
now->addtag(t,x);
return;
}
modify(now->l,l,mid,ml,mr,t,x);
modify(now->r,mid+1,r,ml,mr,t,x);
}
void dfs(node *now,int l,int r,int mn,int mx){
mn=max(mn,now->mn); mx=max(mx,now->mx);
now->push();
if(l==r){
if(0<now->mn)ans[l]=now->mn;
else if(0>now->mx)ans[l]=now->mx;
else ans[l]=0;
return;
}
dfs(now->l,l,mid,mn,mx);
dfs(now->r,mid+1,r,mn,mx);
}
void buildWall(int n,int q,int types[],int ls[],int rs[],int hs[],int __ans[]){
ans=__ans;
build(root=new node(),0,n-1);
for(int i=0;i<q;++i){
modify(root,0,n-1,ls[i],rs[i],types[i],hs[i]);
}
dfs(root,0,n-1,-1e9,1e9);
}
#ifdef WEAK
int __o[500005],__l[500005],__r[500005],__h[500005],__ans[2000005];
int main(){
int n; cin>>n;
int q; cin>>q;
for(int i=0;i<q;++i)cin>>__o[i]>>__l[i]>>__r[i]>>__h[i];
buildWall(n,q,__o,__l,__r,__h,__ans);
for(int i=0;i<n;++i)cout<<__ans[i]<<" ";
cout<<endl;
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |