1. 程式人生 > >未寫完_維護數列

未寫完_維護數列

Code:

#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 500000 + 555;
const int inf = -1223;
int ch[maxn][2], f[maxn], numv[maxn], maxv[maxn], lmax[maxn], rmax[maxn], sumv[maxn], tag[maxn], lazy[maxn], arr[maxn];
int  cnt,
root, siz[maxn]; stack <int> S; struct Operation { inline int init(){ } void recycle(int u) { if(!u) return ; S.push(u); recycle(ch[u][0]); recycle(ch[u][1]); } inline void pushup(int o) { int ls = ch[o][0], rs = ch[o][1]; maxv[
o] = numv[o]; siz[o] = siz[ls] + siz[rs] + 1; int sums = numv[o]; if(ls) maxv[o] = max(maxv[o], maxv[ls]), sums += rmax[ls]; if(rs) maxv[o] = max(maxv[o], maxv[rs]), sums += lmax[rs]; maxv[o] = max(maxv[o], sums); lmax[o] = max(lmax[ls], sumv[ls] + numv[
o] + lmax[rs]); rmax[o] = max(rmax[rs], sumv[rs] + numv[o] + rmax[ls]); } inline void maintain(int o) { maxv[o] = max(numv[o], sumv[o]); lmax[o] = rmax[o] = max(0, sumv[o]); } inline void pushdown(int x,int l,int r) { int mid = (l + r) >> 1, ls = ch[x][0], rs = ch[x][1]; if(lazy[x] != inf) { if(ls){ numv[ls] = lazy[ls] = lazy[x], sumv[ls] = (mid - l) * numv[ls]; maintain(ls); } if(rs){ numv[rs] = lazy[rs] = lazy[x], sumv[rs] = (r - mid) * numv[rs]; maintain(rs); } lazy[x] = inf; } if(tag[x]) { swap(lmax[ls], rmax[ls]); swap(lmax[rs], rmax[rs]); swap(ch[ls][0], ch[ls][1]); swap(ch[rs][0], ch[rs][1]); if(ls) tag[ls] ^= 1; if(rs) tag[rs] ^= 1; tag[x] = 0; } } }T; void build(int l,int r,int fa,int o) { if(l > r) return ; int mid = (l + r) >> 1; o = ++cnt; f[o] = fa, numv[o] = arr[mid]; sumv[o] = sumv[ls] + sumv[rs] + numv[o]; maintain(o); build(l, mid - 1, o, ch[o][0]); build(mid + 1, r, o, ch[o][1]); pushup(o); } inline void rotate(int x) { int old = f[x], oldf = f[old], which = get(x); ch[old][which] = ch[x][which ^ 1], f[ch[old][which]] = old; ch[x][which ^ 1] = old, f[old] = x, f[x] = oldf; if(oldf) ch[oldf][ch[oldf][1] == old] = x; pushup(old); pushup(x); } inline void Splay(int x, int &tar) { int a = f[tar]; for(int fa; (fa = f[x]) != a; rotate(x)); if(f[fa] != a) rotate(get(fa) == get(x) ? fa : x); tar = x; } inline void split(int &a , int nums , int &b) { } int main(){ }