[题解]IOI2014-Wall
English version
We will use lazy tag to solve this problem. Let \(upv[x]\) be the maximum bound of node \(x\), and \(lowv[x]\) be the minimum bound of node \(x\). As we only care about single point value, the leaf node's \(lowv[]\) is the answer. Now the problem is how to maintain those two arrays. Now we assume we are operating on node \(x\), and the value of operation is \(h\).
Part 1: Adding phase
In this part we maintain \(lowv[x]\). If \(lowv[x] < h\) or there's no operation on \(x\), let \(lowv[x] = h\).
Part 2: Removing phase
We maintain \(upv[x]\) just like part one. If \(upv[x] > h\),let \(upv[x] = h\). Notice if \(lowv[x] > h\), let \(lowv[x] = h\).
Part 3: Pushdown.
Just apply Part 1 and 2 on child nodes(\(y\)). If node's \(lowv[y]\) greater than \(upv[x]\), cut it off and vice versa.
Code
1 | //P-4-E |
题意简述
https://codeforces.com/edu/course/2/lesson/5/4/practice/contest/280801/problem/E
或:
https://www.luogu.com.cn/problem/P4560
长度为\(n\)的序列初始为空,维护两种操作:
- Add(L,R,v): 将\([L,R]\)中小于\(v\)的值改变为\(v\)
- Remove(L,R,v):将\([L,R]\)中大于\(v\)的值改变为\(v\)
给出\(m\)个操作,输出操作全部完成后的序列.
\(1 \leq n \leq 2\cdot10^6,1 \leq m \leq 5\cdot10^5\)
思路
对每个节点维护\(upv[]\)和\(lowv[]\),表示该节点值的上限和下限.查询时对每个点做一次单点查询,答案为\(lowv[x]\).
下放节点时\(upv\)和\(lowv\)的关系比较显然,细节请见代码.