【题目链接】
【思路要点】
- 使用Splay维护多个标记进行各种区间操作,代码实现较为困难。
- 内存限制64MB,注意内存回收,避免空间超限。
【代码】
#include<bits/stdc++.h> using namespace std; #define MAXN 500005 #define MAXIN 4500005 struct Node { int father, child[2]; int value, sum; int size, all; int left_max, right_max, mid_max; bool rev, made_same; } a[MAXN]; int available[MAXIN]; int size, root, total; void clear(int x) { a[x].father = 0; a[x].child[0] = 0; a[x].child[1] = 0; a[x].value = 0; a[x].sum = 0; a[x].size = 0; a[x].all = 0; a[x].left_max = 0; a[x].right_max = 0; a[x].mid_max = 0; a[x].rev = false; a[x].made_same = false; } int get(int x) { return a[a[x].father].child[1] == x; } void pushdown(int x) { if (x == 0) return; i