#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
pair<int,int> segtree[8000000];
const int INF = 2e9+20;
int N;
void build(int l = 0, int r = N-1, int p = 1){
if(l == 0 && r == N-1){
segtree[p].f = segtree[p].s = 0;
}
else{
segtree[p].f = -INF; segtree[p].s = INF;
}
if(l == r){
return;
}
int mid = (l+r)>>1;
build(l,mid,p<<1); build(mid+1,r,(p<<1)|1);
}
void push(int p, pair<int,int> newval){
if(newval.s < segtree[p].f){
segtree[p] = {newval.s,newval.s};
return;
}
if(segtree[p].s < newval.f){
segtree[p] = {newval.f,newval.f};
return;
}
segtree[p] = {max(newval.f,segtree[p].f),min(newval.s,segtree[p].s)};
}
void upd(int tarl, int tarr, pair<int,int> val, int l = 0, int r = N-1, int p = 1){
if(r < tarl || l > tarr) return;
if(tarl <= l && r <= tarr){
push(p,val);
return;
}
int mid = (l+r)>>1;
if(l != r){
if(segtree[p].f != -INF || segtree[p].s != INF){
push((p<<1),segtree[p]); push((p<<1)|1,segtree[p]);
segtree[p].f = -INF; segtree[p].s = INF;
}
}
upd(tarl,tarr,val,l,mid,p<<1); upd(tarl,tarr,val,mid+1,(p<<1)|1);
}
void query(int* ans, int l = 0, int r = N-1, int p = 1){
if(l == r){
ans[l] = segtree[p].f;
return;
}
else if(segtree[p].f != -INF || segtree[p].s != INF){
push((p<<1),segtree[p]); push((p<<1)|1,segtree[p]);
segtree[p].f = -INF; segtree[p].s = INF;
}
int mid = (l+r)>>1;
query(ans,l,mid,p<<1); query(ans,mid+1,r,(p<<1)|1);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
N = n;
build();
for(int i = 0;i<k;++i){
if(op[i] == 1){
pair<int,int> val; val.s = INF; val.f = height[i];
upd(left[i],right[i],val);
}
else{
pair<int,int> val; val.f = -INF; val.s = height[i];
upd(left[i],right[i],val);
}
}
query(finalHeight);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
79 ms |
8264 KB |
Output is correct |
3 |
Incorrect |
43 ms |
5972 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |