#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
struct Segtree {
int n;
vector<int> mn;
vector<int> mx;
// 0 : no updates
// 1 : last update was maximum
// 2 : last update was minimum
vector<int> lastUpdate;
Segtree(int sz) {
n=1;
while(n<sz)n*=2;
mn.assign(2*n,0);
mx.assign(2*n,0);
lastUpdate.assign(2*n,0);
}
void pushdown(int x, bool secPush) {
if (secPush) {
pushdown(2*x+1,false);
pushdown(2*x+2,false);
}
if (lastUpdate[x] == 0) return;
if (lastUpdate[x] == 1) {
if (mx[2*x+1] > mx[x]) {
mx[2*x+1] = mx[x];
lastUpdate[2*x+1] = 1;
}
if (mx[2*x+2] > mx[x]) {
mx[2*x+2] = mx[x];
lastUpdate[2*x+2] = 1;
}
mn[2*x+1]=min(mn[2*x+1], mx[x]);
mn[2*x+2]=min(mn[2*x+2], mx[x]);
}
else if (lastUpdate[x] == 2) {
if (mn[2*x+1] < mn[x]) {
mn[2*x+1] = mn[x];
lastUpdate[2*x+1] = 2;
}
if (mn[2*x+2] < mn[x]) {
mn[2*x+2] = mn[x];
lastUpdate[2*x+2] = 2;
}
mx[2*x+1]=max(mx[2*x+1], mn[x]);
mx[2*x+2]=max(mx[2*x+2], mn[x]);
}
lastUpdate[x]=0;
}
void setMax(int l, int r, int v, int x, int lx, int rx) {
if (lx >= r || rx <= l) return;
if (rx-lx==1) {
if (mx[x] > v) {
mx[x]=mn[x]=v;
lastUpdate[x]=1;
}
return;
}
pushdown(x, ((rx-lx)!=2));
if (lx >= l && rx <= r) {
if (mx[x] > v) {
lastUpdate[x]=1;
mx[x]=v;
if (mn[x] > v)mn[x]=v;
}
return;
}
int m=(lx+rx)/2;
setMax(l,r,v,2*x+1,lx,m);
setMax(l,r,v,2*x+2,m,rx);
mx[x]=max(mx[2*x+1],mx[2*x+2]);
mn[x]=min(mn[2*x+1],mn[2*x+2]);
}
void setMax(int l, int r, int v) {
setMax(l, r, v, 0, 0, n);
}
void setMin(int l, int r, int v, int x, int lx, int rx) {
if (lx >= r || rx <= l) return;
if (rx-lx==1) {
if (mn[x] < v) {
mn[x]=mx[x]=v;
lastUpdate[x]=2;
}
return;
}
pushdown(x, ((rx-lx)!=2));
if (lx >= l && rx <= r) {
if (mn[x] < v) {
lastUpdate[x]=2;
mn[x]=v;
if (mx[x] < v) mx[x]=v;
}
return;
}
int m=(lx+rx)/2;
setMin(l,r,v,2*x+1,lx,m);
setMin(l,r,v,2*x+2,m,rx);
mx[x]=max(mx[2*x+1],mx[2*x+2]);
mn[x]=min(mn[2*x+1],mn[2*x+2]);
}
void setMin(int l, int r, int v) {
setMin(l, r, v, 0, 0, n);
}
int get(int i, int x, int lx, int rx) {
if (rx-lx==1) {
cout<<mn[x]<<" "<<mx[x]<<" ";
// assert(mn[x] == mx[x]);
return mx[x];
}
pushdown(x, ((rx-lx)!=2));
int m=(lx+rx)/2;
if (i<m)return get(i,2*x+1,lx,m);
else return get(i,2*x+2,m,rx);
}
int get(int i) {
return get(i,0,0,n);
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
Segtree sg(n);
for (int i=0;i<k;i++) {
if (op[i] == 1) {
sg.setMin(left[i], right[i]+1, height[i]);
}
else {
sg.setMax(left[i], right[i]+1, height[i]);
}
}
for (int i=0;i<n;i++) {
finalHeight[i] = sg.get(i);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |