#include<iostream>
#include<fstream>
#include<algorithm>
//#define int long long
using namespace std;
struct node_t{
int l, r;
int lval, rval, val;
int sum, tag;
#define l(x) tr[x].l
#define r(x) tr[x].r
#define lval(x) tr[x].lval
#define rval(x) tr[x].rval
#define val(x) tr[x].val
#define sum(x) tr[x].sum
#define tag(x) tr[x].tag
}tr[800005];
#define lson(u) (u << 1)
#define rson(u) (u << 1 | 1)
int a[200005];
int pushup(int u){
sum(u) = sum(lson(u)) + sum(rson(u));
val(u) = rval(lson(u)) + lval(rson(u));
if(lval(lson(u)) == r(lson(u)) - l(lson(u)) + 1) lval(u) = lval(lson(u)) + lval(rson(u));
else lval(u) = lval(lson(u));
if(rval(rson(u)) == r(rson(u)) - l(rson(u)) + 1) rval(u) = rval(rson(u)) + rval(lson(u));
else rval(u) = rval(rson(u));
return 0;
}
int build(int u, int l, int r){
l(u) = l, r(u) = r, tag(u) = 0;
if(l == r){
sum(u) = a[l];
if(a[l] == 0) lval(u) = rval(u) = val(u) = 1;
else lval(u) = rval(u) = val(u) = 0;
return 0;
}
int mid = (l + r) >> 1;
build(lson(u), l, mid);
build(rson(u), mid + 1, r);
return pushup(u), 0;
}
int pushdown(int u){
if(tag(u) == 0) return 0;
if(l(u) == r(u)) return tag(u) = 0, 0;
if(tag(u) == 1){
lval(lson(u)) = rval(lson(u)) = val(lson(u)) = r(lson(u)) - l(lson(u)) + 1,
lval(rson(u)) = rval(rson(u)) = val(rson(u)) = r(rson(u)) - l(rson(u)) + 1;
sum(lson(u)) = sum(rson(u)) = 0;
tag(lson(u)) = tag(rson(u)) = 1, tag(u) = 0;
return 0;
}
if(tag(u) == 2){
lval(lson(u)) = rval(lson(u)) = val(lson(u)) = 0,
lval(rson(u)) = rval(rson(u)) = val(rson(u)) = 0;
sum(lson(u)) = r(lson(u)) - l(lson(u)) + 1, sum(rson(u)) = r(rson(u)) - l(rson(u)) + 1;
tag(lson(u)) = tag(rson(u)) = 2, tag(u) = 0;
return 0;
}
return 0;
}
int modify(int u, int l, int r, int v){
if(l > r(u) || r < l(u)) return 0;
if(l >= l(u) && r <= r(u)){
if(v == 0){
lval(u) = rval(u) = val(u) = r(u) - l(u) + 1;
sum(u) = 0, tag(u) = 1;
}
else{
lval(u) = rval(u) = val(u) = 0;
sum(u) = r(u) - l(u) + 1, tag(u) = 2;
}
return 0;
}
pushdown(u);
modify(lson(u), l, r, v), modify(rson(u), l, r, v);
return pushup(u), 0;
}
int query(int u, int l, int r){
if(l > r(u) || r < l(u)) return 0;
if(l >= l(u) && r <= r(u))
return sum(u);
pushdown(u);
return query(lson(u), l, r) + query(rson(u), l, r);
}
int query0(int u, int l, int r){
return (r - l + 1) - query(1, l, r);
}
int find(int l, int r, int v){
int L = l;
while(l < r){
int mid = (l + r) >> 1;
if(query0(1, L, mid) < v)
l = mid + 1;
else r = mid;
}
return r;
}
int solve(int l0, int r0, int l1, int r1){
int x = query(1, l0, r0);
modify(1, l0, r0, 0);
int pos = find(l1, r1, x);
modify(1, l1, pos, 1);
return 0;
}
int n, m;
signed main(){
//ios::sync_with_stdio(0);
//cin.tie(0), cout.tie(0);
return 0;
}
标签:return,int,rson,保存,脑洞,tag,lson,治疗仪,define
From: https://www.cnblogs.com/AzusidNya/p/17774708.html