#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct SegmentTree {
vector<int> tree, minLazy, maxLazy;
void build(int N, int idx, int l, int r) {
if (idx == 1) {
tree.resize(4 * N);
minLazy.resize(4 * N);
maxLazy.resize(4 * N);
}
minLazy[idx] = -1; maxLazy[idx] = -1;
if (l != r) {
int mid = (l + r) >> 1;
build(N, idx * 2, l, mid);
build(N, idx * 2 + 1, mid + 1, r);
}
return;
}
void push(int idx, int l, int r) {
if (minLazy[idx] == -1 && maxLazy[idx] == -1) return;
int mid = (l + r) >> 1;
if (maxLazy[idx] != -1) {
tree[idx] = max(maxLazy[idx], tree[idx]);
if (l != r) {
push(2*idx, l, mid);
push(2*idx+1, mid + 1, r);
maxLazy[idx*2] = maxLazy[idx];
maxLazy[idx*2+1] = maxLazy[idx];
}
maxLazy[idx] = -1;
}
if (minLazy[idx] != -1) {
tree[idx] = min(minLazy[idx], tree[idx]);
if (l != r) {
push(2*idx, l, mid);
push(2*idx+1, mid + 1, r);
minLazy[idx*2] = minLazy[idx];
minLazy[idx*2+1] = minLazy[idx];
}
minLazy[idx] = -1;
}
}
void RMaxU(int idx, int l, int r, int ql, int qr, int val) {
push(idx, l, r);
if (qr < l || ql > r) return;
if (l >= ql && qr >= r) {
maxLazy[idx] = val;
push(idx, l, r);
return;
}
int mid = (l + r) >> 1;
if (l != r) {
RMaxU(idx*2, l, mid, ql, qr, val);
RMaxU(idx*2+1, mid + 1, r, ql, qr, val);
}
tree[idx] = max(tree[idx*2], tree[idx*2+1]);
}
void RMinU(int idx, int l, int r, int ql, int qr, int val) {
push(idx, l, r);
if (qr < l || ql > r) return;
if (l >= ql && qr >= r) {
minLazy[idx] = val;
push(idx, l, r);
return;
}
int mid = (l + r) >> 1;
if (l != r) {
RMinU(idx*2, l, mid, ql, qr, val);
RMinU(idx*2+1, mid + 1, r, ql, qr, val);
}
tree[idx] = min(tree[idx*2], tree[idx*2+1]);
}
int query(int idx, int l, int r, int k) {
push(idx, l, r);
if (l == r) {
return tree[idx];
}
int mid = (l + r) >> 1;
if (k <= mid) {
return query(idx*2, l, mid, k);
} else {
return query(idx*2+1, mid + 1, r, k);
}
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
SegmentTree seg;
seg.build(n, 1, 0, n - 1);
for (int i = 0; i < k; i++) {
if (op[i] == 1) {
seg.RMaxU(1, 0, n-1, left[i], right[i], height[i]);
} else {
seg.RMinU(1, 0, n-1, left[i], right[i], height[i]);
}
}
for (int i = 0; i < n; i++) {
finalHeight[i] = seg.query(1, 0, n - 1, i);
}
}
/*
int main()
{
int n;
int k;
int i, j;
int status = 0;
status = scanf("%d%d", &n, &k);
assert(status == 2);
int* op = (int*)calloc(sizeof(int), k);
int* left = (int*)calloc(sizeof(int), k);
int* right = (int*)calloc(sizeof(int), k);
int* height = (int*)calloc(sizeof(int), k);
int* finalHeight = (int*)calloc(sizeof(int), n);
for (i = 0; i < k; i++){
status = scanf("%d%d%d%d", &op[i], &left[i], &right[i], &height[i]);
assert(status == 4);
}
buildWall(n, k, op, left, right, height, finalHeight);
for (j = 0; j < n; j++)
printf("%d\n", finalHeight[j]);
return 0;
}*/
/*
10 6
1 1 8 4
2 4 9 1
2 3 6 5
1 0 5 3
1 2 2 5
2 6 7 0
*/
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |