标签:描述 xxx efi clu inline == 是你 复杂度 define
来自FallDream的博客,未经允许,请勿转载,谢谢。
#include<iostream> #include<cstdio> #include<cstring> #define ll long long #define MN 500005 #define getchar() (*S++) char BB[1<<26],*S=BB; using namespace std; inline int read() { int x = 0; char ch = getchar(); while(ch < ‘0‘ || ch > ‘9‘) ch = getchar(); while(ch >= ‘0‘ && ch <= ‘9‘){x = x * 10 + ch - ‘0‘;ch = getchar();} return x; } inline ll llread() { ll x = 0; char ch = getchar(); while(ch < ‘0‘ || ch > ‘9‘)ch = getchar(); while(ch >= ‘0‘ && ch <= ‘9‘){x = x * 10 + ch - ‘0‘;ch = getchar();} return x; } struct data { ll x[4][4]; data(){} data(ll a,ll b,ll c) { memset(x,0,sizeof(x)); x[0][0]=x[3][3]=a;x[1][1]=b; x[2][2]=c;x[0][1]=max(a,b); x[1][2]=max(b,c);x[2][3]=max(a,c); x[0][2]=x[1][3]=x[0][3]=max(a,max(b,c)); } friend data operator + (data a,data b) { data c;memset(c.x,0,sizeof(c.x)); for(int l=1;l<=4;++l) for(int i=0;i+l-1<4;++i) { int j=i+l-1;c.x[i][j]=0; for(int k=i;k<=j;++k) c.x[i][j]=max(c.x[i][j],a.x[i][k]+b.x[k][j]); } return c; } }s[MN+5]; int fa[MN+5],sz[MN+5],c[MN+5][2],rt=0,mark,A[MN+5],L[MN+5],B[MN+5],C[MN+5],n,cnt=0,q[MN+5],top=0; ll size[MN+5],tot; int tms=0; inline void update(int x) { s[x]=(data){1LL*A[x]*L[x],1LL*B[x]*L[x],1LL*C[x]*L[x]}; if(c[x][0]) s[x]=s[c[x][0]]+s[x]; if(c[x][1]) s[x]=s[x]+s[c[x][1]]; size[x]=size[c[x][0]]+size[c[x][1]]+L[x]; sz[x]=sz[c[x][0]]+sz[c[x][1]]+1; } int Find(int x,ll pos) { ll Sz1=size[c[x][0]],Sz2=Sz1+L[x]; if((Sz1<pos||(!c[x][0]&&!pos))&&Sz2>=pos) return x; if(Sz1>=pos) return Find(c[x][0],pos); return tot+=Sz2,Find(c[x][1],pos-Sz2); } void ins(int&x,int ai,int bi,int ci,ll pos,int len,int last=0) { if(!x) { x=++cnt;s[x]=data(1LL*ai*len,1LL*bi*len,1LL*ci*len); L[x]=size[x]=len;A[x]=ai;B[x]=bi;C[x]=ci;sz[x]=1;fa[x]=last; return; } ll Sz=size[c[x][0]]+L[x]; if(Sz<=pos) ins(c[x][1],ai,bi,ci,pos-Sz,len,x); else ins(c[x][0],ai,bi,ci,pos,len,x); update(x); if(max(sz[c[x][0]],sz[c[x][1]])>0.7*sz[x]) mark=x; } void Modify(int x,int k,ll pos,int Len) { if(x==k) { L[x]=Len;update(x); return; } if(size[c[x][0]]>=pos) Modify(c[x][0],k,pos,Len); else Modify(c[x][1],k,pos-L[x]-size[c[x][0]],Len); update(x); } void Dfs(int x) { if(c[x][0]) Dfs(c[x][0]); q[++top]=x; if(c[x][1]) Dfs(c[x][1]); } void Build(int&x,int l,int r,int last) { if(l>r) {x=0;return;} int mid=l+r>>1;x=q[mid];fa[x]=last; Build(c[x][0],l,mid-1,x); Build(c[x][1],mid+1,r,x); update(x); } void rebuild(int x) { mark=top=0;Dfs(x);int y=fa[x]; if(!y) Build(rt,1,top,0); else Build(c[y][c[y][1]==x],1,top,y); } int main() { fread(BB,1,1<<26,stdin); n=read();ins(rt,0,0,0,0,0);ll pre=0; for(int i=1;i<=n;++i) { ll p=llread(); int ai=read(),bi=read(),ci=read(),x=read(); tot=tms=0;int k=Find(rt,p); if(tot+size[c[k][0]]+L[k]!=p) { ll Left=tot+size[c[k][0]]+L[k]-p; tms=0;Modify(rt,k,p,L[k]-Left); ins(rt,ai,bi,ci,p,x);if(mark) rebuild(mark); ins(rt,A[k],B[k],C[k],p+x,Left); } else ins(rt,ai,bi,ci,p,x); printf("%lld\n",s[rt].x[0][3]-pre); pre=s[rt].x[0][3];if(mark) rebuild(mark); } return 0; }
标签:描述 xxx efi clu inline == 是你 复杂度 define
原文地址:http://www.cnblogs.com/FallDream/p/bzoj4906.html