Title Description
Given an initial element of \ (0 \) is the number of columns, and \ (K \) operations:
- The interval \ ([L, R] \ ) in an element of \ (H \) take \ (max \)
- The interval \ ([L, R] \ ) in an element of \ (H \) take \ (min \)
Problem-solving ideas
First, to be able to see that this is a problem in the tree line.
So how do we build a node of it?
First, for each node of the tree line, we remember the two markers \ (Min \) and \ (Max \) .
Because the topics related to \ (min \) and \ (max \) operation, so it should be difficult to think provided two such markers.
The significance of these two markers:
- \ (Min [rt] \) represents the number \ (RT \) node comprises a section \ (min \) value of the flag
- \ (Max [rt] \) represents the number \ (RT \) node comprises a section \ (max \) value of the flag
How it seems, and did not speak the same
Because the title last only asks each leaf node, so we do not care what the value of some node.
We just need to with each node and two marks: \ (Min \) and \ (Max \) , because we need both to update the leaves).
And these two markers can be updated by the interval to maintain.
How to deal with markers
Processing labeled with three operations: initialization, and downstream marking tag.
Simple analysis Initialization:
As our tag is used to update the child nodes (ie, the son of his father's mark \ (Max \) take \ (max \) , father of \ (Min \) take \ (min \) )
so we put \ (Max \) assigned to the minimum value, \ (Min \) assigned the maximum value:
Max[rt] = 0, Min[rt] = 0x3f3f3f3f;
Then look at marking:
inline void fMax(int rt, int h) { Min[rt] = max(Min[rt], h), Max[rt] = max(Max[rt], h); }
inline void fMin(int rt, int h) { Min[rt] = min(Min[rt], h), Max[rt] = min(Max[rt], h); }
In fact, these two functions are essentially the same
Let's analyze:
If we put a period to the interval \ (h \) take \ (max \) , then this section \ (Min \) mark and \ (Max \) tags should \ (h \) to take \ (max \) .
I do not make this specific analysis: Why do you think can be your ownIt can also be emotional understanding
So marking on the finished \ (QwQ \)
Finally, look at the pass mark \ (pushdown \)
inline void pushdown(int rt) {
fMin(lc(rt), Min[rt]), fMin(rc(rt), Min[rt]);
fMax(lc(rt), Max[rt]), fMax(rc(rt), Max[rt]);
Max[rt] = 0, Min[rt] = 0x3f3f3f3f;
}
In fact, this and similar marking, is to use his father's son updates.
How to answer output
This fact, as long traverse over the tree line, the leaf node \ (Max \) or \ (Min \) output can be.
Details Notes
- Segment tree space open \ (4 \) times
- Remember \ (pushdown \) after initialization also
Reference Code
/*--------------------------------
Author: The Ace Bee
Blog: www.cnblogs.com/zsbzsb
This code is made by The Ace Bee
--------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
}
const int _ = 2000010;
int n, k, Min[_ << 2], Max[_ << 2];
inline int lc(int rt) { return rt << 1; }
inline int rc(int rt) { return rt << 1 | 1; }
inline void fMax(int rt, int h) { Min[rt] = max(Min[rt], h), Max[rt] = max(Max[rt], h); }
inline void fMin(int rt, int h) { Min[rt] = min(Min[rt], h), Max[rt] = min(Max[rt], h); }
inline void pushdown(int rt) {
fMin(lc(rt), Min[rt]), fMin(rc(rt), Min[rt]);
fMax(lc(rt), Max[rt]), fMax(rc(rt), Max[rt]);
Max[rt] = 0, Min[rt] = 0x3f3f3f3f;
}
inline void update(int rt, int l, int r, int x, int y, int h, int t) {
if (x <= l && r <= y) {
if (t == 1)
return fMax(rt, h);
else
return fMin(rt, h);
}
int mid = (l + r) >> 1;
pushdown(rt);
if (x <= mid) update(lc(rt), l, mid, x, y, h, t);
if (y > mid) update(rc(rt), mid + 1, r, x, y, h, t);
}
inline void query(int rt, int l, int r) {
if (l == r) { printf("%d\n", Max[rt]); return ; }
int mid = (l + r) >> 1;
pushdown(rt);
query(lc(rt), l, mid);
query(rc(rt), mid + 1, r);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(k);
for (rg int i = 1; i <= n << 2; ++i)
Max[i] = 0, Min[i] = 0x3f3f3f3f;
for (rg int t, l, r, h, i = 1; i <= k; ++i)
read(t), read(l), read(r), read(h), update(1, 1, n, l + 1, r + 1, h, t);
query(1, 1, n);
return 0;
}
End Sahua \ (qwq \)