#include "wall.h"
#include<bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
struct SegTree{
int N;
vector<int>tree;
vector<pair<int,int>>mn,mx;
SegTree(int n){
N=1;
while(N<n) N<<=1;
tree.assign(2*N,0);
mn.assign(2*N,{-1,-1});
mx.assign(2*N,{-1,-1});
}
void push1(int v){
if(mx[v].ff==-1) return;
mx[v<<1]=max(mx[v],mx[v<<1]);
mx[v<<1|1]=max(mx[v],mx[v<<1|1]);
tree[v<<1]=max(tree[v<<1],mx[v].ff);
tree[v<<1|1]=max(tree[v<<1|1],mx[v].ff);
mx[v]={-1,-1};
}
void push2(int v){
if(mn[v].ff==-1) return;
mn[v<<1]=min(mn[v<<1],mn[v]);
mn[v<<1|1]=min(mn[v<<1|1],mn[v]);
tree[v<<1]=min(tree[v<<1],mn[v].ff);
tree[v<<1|1]=min(tree[v<<1|1],mn[v].ff);
mn[v]={-1,-1};
}
void push(int v){
if(mn[v].ss>mx[v].ss){
push1(v);
push2(v);
}
else{
push2(v);
push1(v);
}
}
void update(int v,int l,int r,int ql,int qr,int x,int id,int c){
if(l>=qr || ql>=r) return;
if(l>=ql && qr>=r){
if(r-l>1) push(v);
if(id&1) mx[v]={x,c},tree[v]=max(x,tree[v]);
else mn[v]={x,c},tree[v]=min(tree[v],x);
return;
}
push(v);
int mid=(l+r)/2;
update(v<<1,l,mid,ql,qr,x,id,c);
update(v<<1|1,mid,r,ql,qr,x,id,c);
}
void update(int l,int r,int x,int id,int c){
return update(1,0,N,l,r,x,id,c);
}
int get(int v,int l,int r,int id){
if(r-l==1){
return tree[v];
}
push(v);
int mid=(l+r)/2;
if(mid>id) return get(v<<1,l,mid,id);
return get(v<<1|1,mid,r,id);
}
int get(int id){
return get(1,0,N,id);
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
SegTree S(n);
for(int i=0;i<k;i++){
S.update(left[i],right[i]+1,height[i],op[i],i);
}
for(int i=0;i<n;i++){
finalHeight[i]=S.get(i);
}
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
80 ms |
8228 KB |
Output is correct |
3 |
Incorrect |
146 ms |
4948 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |