SHOI2015 脑洞治疗仪
珂朵莉树有个**用处,适用范围这么窄,还必须要求随机数据
……
嗯,真香
对于大多数题目,出题人不会刻意去卡珂朵莉树(那时可能还没有珂朵莉树),即使去卡,因为OI是按照通过的测试点数目得分,不太可能所有的测试点都能将珂朵莉卡掉。而珂朵莉树好想好敲,可以使某些题目难度下降一个档次。所以珂朵莉树对于骗分还是很有用处的
比如这道题,当时珂朵莉树还没有出世,数据自然不会刻意去卡珂朵莉树,所以我们可以愉快的用珂朵莉树A掉此题
区间修改直接摊平,区间查询暴力查找所有区间,填补操作就枚举+摊平
珂朵莉树使此题的代码难度和思维难度都下降了一个档次
这就是暴力数据结构的美感
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#define LL long long
#define IT set <hhh> :: iterator
using namespace std;
const LL mod = 1e9+7;
LL read() {
LL k = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9')
k = k * 10 + c - 48, c = getchar();
return k * f;
}
struct hhh {
int l, r; mutable int v;
hhh(int nl, int nr = -1, int nv = 0) : l(nl), r(nr), v(nv) {};
bool operator < (const hhh &y) const {
return l < y.l;
}
}; set <hhh> q;
IT split(int pos) {
IT it = q.lower_bound(hhh(pos));
if(it != q.end() && it->l == pos) return it;
--it;
int nl = it->l, nr = it->r, nv = it->v;
q.erase(it); q.insert(hhh(nl, pos-1, nv));
return q.insert(hhh(pos, nr, nv)).first;
}
void assign(int l, int r, int v) {
IT itr = split(r+1), itl = split(l);
q.erase(itl, itr); q.insert(hhh(l, r, v));
}
int query(int l, int r) {
int ans = 0, maxn = 0;
IT itr = split(r+1), itl = split(l);
for(; itl != itr; ++itl) {
if(itl->v == 0) ans += itl->r - itl->l + 1;
else ans = 0;
maxn = max(ans, maxn);
}
return maxn;
}
int sum(int l, int r) {
int ans = 0;
IT itr = split(r+1), itl = split(l);
for(; itl != itr; ++itl)
if(itl->v == 1) ans += itl->r - itl->l + 1;
return ans;
}
void fill(int l, int r, int cnt) {
IT itr = split(r+1), itl = split(l);
for(; itl != itr && cnt; ++itl) {
if(itl->v == 0) {
if(cnt >= itl->r - itl->l + 1)
cnt -= (itl->r - itl->l + 1), itl->v = 1;
else assign(itl->l, itl->l + cnt - 1, 1), cnt = 0;
}
}
}
int main() {
int n = read(), m = read();
q.insert(hhh(1, n, 1));
while(m--) {
int opt = read(), l = read(), r = read();
if(opt == 0) assign(l, r, 0);
else if(opt == 1) {
int nl = read(), nr = read();
int cnt = sum(l, r); assign(l, r, 0);
fill(nl, nr, cnt);
}
else if(opt == 2) {
printf("%d\n", query(l, r));
}
}
return 0;
}