Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;const int MAXN = 100010;const int INF = 0x7fffffff;#define lson tr[x].ch[0]#define rson tr[x].ch[1]struct Node{int ch[2], fa, v, size;bool rv;//是否翻转,因为偶数次翻转无效,所以可以用bool,位运算void set(int x){v=x; ch[0]=ch[1]=fa=rv=0; size=1;}}tr[MAXN];int n, m, root, tot, l, r, x1, x2;void updata(int x){//维护sizeif( !x ) return;tr[x].size = 1 + tr[lson].size + tr[rson].size;}void pushdown(int x){//打标记必备if( !x ) return;if( tr[x].rv ){//x的子节点集合为翻转区间tr[lson].rv ^= 1; tr[rson].rv ^= 1;//标记下传tr[x].rv = 0;//消除int t = lson; lson = rson; rson = t;//当前层翻转