codeforces739C - Skills &&金中市队儿童节常数赛

http://codeforces.com/problemset/problem/739/C 先上链接

这道题 对于蒟蒻的我来说还是很有难度的 调了很久

对于我的代码 mx2是答案 mx1代表单调 mx2双调 带l,r的代表从哪边开始 剩下的自己加油看吧 不是很长来着

#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int M=3e5+233,maxM=M<<1;
LL tag[maxM],vl[maxM],vr[maxM];
int lc[maxM],rc[maxM],sz[maxM],mx1l[maxM],mx1r[maxM],mx2[maxM],mx2l[maxM],mx2r[maxM];
int sum,n,m,L,R,w;
int read(){
    int ans=0,f=1,c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
    return ans*f;
}
void up(int x){
    int l=lc[x],r=rc[x],v1,v2;
    vl[x]=vl[l]; vr[x]=vr[r];
    mx1l[x]=mx1l[l]; if(mx1l[l]==sz[l]&&vr[l]>vl[r]) mx1l[x]+=mx1l[r];
    mx1r[x]=mx1r[r]; if(mx1r[r]==sz[r]&&vl[r]>vr[l]) mx1r[x]+=mx1r[l];
    /*mx2l[x]*/ v1=mx2l[l]; if(mx2l[l]==sz[l]&&vr[l]>vl[r]) v1+=mx1l[r];
                v2=0; if(mx1r[l]==sz[l]&&vl[r]>vr[l]) v2=mx1r[l]+mx2l[r]; 
    mx2l[x]=max(v1,v2);
    /*mx2r[x]*/ v1=mx2r[r]; if(mx2r[r]==sz[r]&&vl[r]>vr[l]) v1+=mx1r[l];
                v2=0; if(mx1l[r]==sz[r]&&vr[l]>vl[r]) v2=mx1l[r]+mx2r[l];
    mx2r[x]=max(v1,v2);
    mx2[x]=max(mx2[l],mx2[r]);
    if(vr[l]>vl[r]) mx2[x]=max(mx2[x],mx2r[l]+mx1l[r]);
    if(vr[l]<vl[r]) mx2[x]=max(mx2[x],mx2l[r]+mx1r[l]);
}
void add(int x,LL w){vl[x]+=w; vr[x]+=w; tag[x]+=w;}
void down(int x){
    int l=lc[x],r=rc[x];
    add(l,tag[x]); add(r,tag[x]);
    tag[x]=0;
}
void build(int l,int r){
    int x=++sum; sz[x]=r-l+1;
    if(l==r){vl[x]=vr[x]=read(); mx1l[x]=mx1r[x]=mx2[x]=mx2l[x]=mx2r[x]=1; return ;}
    int mid=(l+r)>>1;
    lc[x]=sum+1; build(l,mid);
    rc[x]=sum+1; build(mid+1,r);
    up(x);
}
void insert(int x,int l,int r){
    if(L<=l&&r<=R){add(x,w); return ;}
    int mid=(l+r)>>1;
    if(tag[x]) down(x);
    if(L<=mid) insert(lc[x],l,mid);
    if(R>mid)  insert(rc[x],mid+1,r);
    up(x);
}
int main()
{
    n=read(); build(1,n);
     m=read(); for(int i=1;i<=m;i++) L=read(),R=read(),w=read(),insert(1,1,n),printf("%d\n",mx2[1]);
    return 0;
}
View Code

 

posted @ 2017-06-06 14:51  友人Aqwq  阅读(383)  评论(0编辑  收藏  举报