#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
struct Segtree {
int n;
vector<int> lzMin, lzMax;
const int minConst = 1e9;
const int maxConst = 0;
Segtree(int sz) {
n=1;
while(n<sz)n*=2;
lzMin.assign(2*n,minConst);
lzMax.assign(2*n,maxConst);
}
void pushdown(int x) {
if (lzMin[x] == minConst && lzMax[x] == maxConst) {
return;
}
lzMin[2*x+1] = min(lzMin[2*x+1], lzMin[x]);
lzMin[2*x+2] = min(lzMin[2*x+2], lzMin[x]);
lzMax[2*x+1] = max(lzMax[2*x+1], lzMax[x]);
lzMax[2*x+2] = max(lzMax[2*x+2], lzMax[x]);
if (lzMax[x] > lzMin[2*x+1]) {
lzMin[2*x+1] = lzMax[x];
}
if (lzMax[x] > lzMin[2*x+2]) {
lzMin[2*x+2] = lzMax[x];
}
if (lzMin[x] < lzMax[2*x+1]) {
lzMax[2*x+1] = lzMin[x];
}
if (lzMin[x] < lzMax[2*x+2]) {
lzMax[2*x+2] = lzMin[x];
}
lzMin[x] = minConst;
lzMax[x] = maxConst;
}
void set(int l, int r, int v, int x, int lx, int rx, bool isMax=false) {
if (lx >= r || rx <= l) return;
if (rx - lx == 1) {
if (isMax) {
if (lzMax[x] < v) {
lzMax[x] = v;
}
if (lzMin[x] < v) {
lzMin[x] = v;
}
}
else {
if (lzMin[x] > v) {
lzMin[x] = v;
}
if (lzMax[x] > v) {
lzMax[x] = v;
}
}
return;
}
pushdown(x);
if (lx >= l && rx <= r) {
if (isMax) {
if (lzMax[x] < v) {
lzMax[x] = v;
}
if (lzMin[x] < v) {
lzMin[x] = v;
}
}
else {
if (lzMin[x] > v) {
lzMin[x] = v;
}
if (lzMax[x] > v) {
lzMax[x] = v;
}
}
return;
}
int m=(lx+rx)/2;
set(l, r, v, 2*x+1, lx, m, isMax);
set(l, r, v, 2*x+2, m, rx, isMax);
}
void setMax(int l, int r, int v) {
set(l, r, v, 0, 0, n, true);
}
void setMin(int l, int r, int v) {
set(l, r, v, 0, 0, n, false);
}
int get(int i, int x, int lx, int rx) {
if (rx-lx==1) {
return lzMax[x];
}
pushdown(x);
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[], vector<int> &finHeight) {
Segtree sg(n);
for (int i=0;i<k;i++) {
if (op[i] == 1) {
sg.setMax(left[i], right[i]+1, height[i]);
}
else {
sg.setMin(left[i], right[i]+1, height[i]);
}
vector<int> out;
for (int i=0;i<n;i++) {
out.push_back(sg.get(i));
}
}
for (int i=0;i<n;i++) {
finHeight[i] = sg.get(i);
}
}
Compilation message
/usr/bin/ld: /tmp/ccY3BomR.o: in function `main':
grader.cpp:(.text.startup+0x133): undefined reference to `buildWall(int, int, int*, int*, int*, int*, int*)'
collect2: error: ld returned 1 exit status