#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include "wall.h"
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int f[]){
for (int i=0; i<n; i++) {
f[i] = 0;
}
vector<int> stop(n, -1), start(n, -1);
for (int i=0; i<k; i++) {
if (op[i] == 2) break;
int l = left[i], r = right[i];
start[l] = max(start[l], height[i]);
stop[r] = max(stop[r], height[i]);
}
multiset<int> ms;
ms.insert(0);
for (int i=0; i<n; i++) {
if (start[i] != -1) ms.insert(start[i]);
f[i] = *ms.rbegin();
if (stop[i] != -1) ms.erase(ms.find(stop[i]));
}
for (int i=0; i<n; i++) {
start[i] = stop[i] = 1e9;
}
for (int i=0; i<k; i++) {
if (op[i] == 1) continue;
int l = left[i], r = right[i];
start[l] = min(start[l], height[i]);
stop[r] = min(stop[r], height[i]);
}
ms.clear();
ms.insert(1e9);
for (int i=0; i<n; i++) {
if (start[i] != 1e9) {
ms.insert(start[i]);
}
f[i] = min(f[i], *ms.begin());
if (stop[i] != 1e9) {
ms.erase(ms.find(stop[i]));
}
}
return;
}