This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int O=0;
const int N=2e6+5;
struct segtree{
int t[4*N]={(int)-1e9};
map<pair<int,int>,int>M;
void build(int v,int tl,int tr){
M[{tl,tr}]=v;
if(tl==tr){
}
else {
int tm=(tl+tr)/2;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
}
}
void reset(){
for(int i=0;i<N;i++)t[i]=1e9;
}
void update_min(int v,int tl,int tr,int l,int r,int x){
if(tl>=l&&tr<=r){
t[v]=min(t[v],x);
return;
}
if(tl>r||tr<l)return;
int tm=(tl+tr)/2;
update_min(v*2,tl,tm,l,r,x);
update_min(v*2+1,tm+1,tr,l,r,x);
}
void update_max(int v,int tl,int tr,int l,int r,int x){
if(tl>=l&&tr<=r){
t[v]=max(t[v],x);
return;
}
if(tl>r||tr<l)return;
int tm=(tl+tr)/2;
update_max(v*2,tl,tm,l,r,x);
update_max(v*2+1,tm+1,tr,l,r,x);
}
int query_max(int v){
v=M[{v,v}];
int ans=-1e9;
while(v){
ans=max(ans,t[v]);
v/=2;
}
return ans;
}
int query_min(int v){
v=M[{v,v}];
int ans=1e9;
while(v){
ans=min(ans,t[v]);
v/=2;
}
return ans;
}
}segg;
void buildWall(int n, int k, int op[], int left[], int right[],int height[], int finalHeight[]){
for(int i=0;i<n;i++)finalHeight[i]=0;
if(n<=10000&&k<=5000){
for(int i=0;i<k;i++){
if(op[i]==1){
for(int j=left[i];j<=right[i];j++)finalHeight[j]=max(finalHeight[j],height[i]);
}
else {
for(int j=left[i];j<=right[i];j++)finalHeight[j]=min(finalHeight[j],height[i]);
}
}
return;
}
segg.build(1,0,n-1);
for(int i=0;i<k;i++){
if(op[i]==2)break;
segg.update_max(1,0,n-1,left[i],right[i],height[i]);
}
for(int i=0;i<n;i++){
int u=segg.query_max(i);
finalHeight[i]=u;
}
segg.reset();
for(int i=0;i<n;i++)segg.update_min(1,0,n-1,i,i,finalHeight[i]);
for(int i=0;i<k;i++){
if(op[i]==1)continue;
segg.update_min(1,0,n-1,left[i],right[i],height[i]);
}
for(int i=0;i<n;i++){
finalHeight[i]=segg.query_min(i);
}
}/*
int main(){
int n,k;
cin>>n>>k;
int op[k];
int l[k];
int r[k];
int x[k];
for(int i=0;i<k;i++)cin>>op[i]>>l[i]>>r[i]>>x[i];
int ans[n];
for(int i=0;i<n;i++)ans[i]=0;
buildWall(n,k,op,l,r,x,ans);
for(int i=0;i<n;i++)cout<<ans[i]<<" ";
}*/
/*
10
6
1 1 8 4
2 4 9 1
2 3 6 5
1 0 5 3
1 2 2 5
2 6 7 0
10
4
1 1 8 4
1 0 5 3
1 2 2 5
2 6 7 0
3 4 5 4 4 4 0 0 4 0
*/
# | 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... |