样例过,全WA

P2572 [SCOI2010] 序列操作

LordLaffey @ 2021-04-13 18:11:35

RT

#include<iostream>
#include<cstdio>
using namespace std;
const int SIZE=1e5;
int ls(int i){return i<<1;}
int rs(int i){return i<<1|1;}
int _max(int x,int y){return x>y?x:y;}
void _swap(int &x,int &y){int c=x;x=y,y=c;}
int input[SIZE+10],len_;
struct node{

    int l,r;
    int sum_0,sum_1,l_0,l_1,r_0,r_1,all_0,all_1;
    int lz_qf,lz_fz;

}tree[SIZE*4+10];
node Treetmp[SIZE+10];
int len(int i){return tree[i].r-tree[i].l+1;}

void up(int i){

    tree[i].all_0=_max(tree[ls(i)].all_0,_max(tree[rs(i)].all_0,tree[ls(i)].r_0+tree[rs(i)].l_0));
    tree[i].all_1=_max(tree[ls(i)].all_1,_max(tree[rs(i)].all_1,tree[ls(i)].r_1+tree[rs(i)].l_1));

}

void update(int i){

    tree[i].sum_0=tree[ls(i)].sum_0+tree[rs(i)].sum_0;
    tree[i].sum_1=tree[ls(i)].sum_1+tree[rs(i)].sum_1;
    tree[i].l_0=tree[ls(i)].l_0;tree[i].r_0=tree[rs(i)].r_0;
    tree[i].l_1=tree[ls(i)].l_1;tree[i].r_1=tree[rs(i)].r_1;
    if(len(ls(i))==tree[ls(i)].sum_1) tree[i].l_1+=tree[rs(i)].l_1;
    if(len(rs(i))==tree[rs(i)].sum_1) tree[i].r_1+=tree[ls(i)].r_1;
    up(i);

}

void fz0(int i){

    tree[i].sum_0=tree[i].l_0=tree[i].r_0=tree[i].all_0=tree[i].r-tree[i].l+1,
    tree[i].sum_1=tree[i].l_1=tree[i].r_1=tree[i].all_1=0;

}

void fz1(int i){

    tree[i].sum_1=tree[i].l_1=tree[i].r_1=tree[i].all_1=tree[i].r-tree[i].l+1,
    tree[i].sum_0=tree[i].l_0=tree[i].r_0=tree[i].all_0=0;

}

void qf(int i){

    _swap(tree[i].sum_1,tree[i].sum_0),
    _swap(tree[i].l_1,tree[i].l_0),
    _swap(tree[i].r_1,tree[i].r_0),
    _swap(tree[i].all_1,tree[i].all_0);

}

void lztage(int i){

    if(tree[i].lz_fz==0) fz0(ls(i)),fz0(rs(i));
    if(tree[i].lz_fz==1) fz1(ls(i)),fz1(rs(i));
    if(tree[i].lz_qf) qf(ls(i)),qf(rs(i));
    if(tree[i].lz_fz!=-1)
    tree[ls(i)].lz_qf=tree[rs(i)].lz_qf=0,tree[ls(i)].lz_fz=tree[rs(i)].lz_fz=tree[i].lz_fz;
//  if(tree[ls(i)].lz_fz!=-1&&tree[i].lz_qf) tree[ls(i)].lz_fz=1-tree[ls(i)].lz_fz;
//  if(tree[rs(i)].lz_fz!=-1&&tree[i].lz_qf) tree[rs(i)].lz_fz=1-tree[rs(i)].lz_fz;
    if(tree[i].lz_qf) tree[ls(i)].lz_qf^=1,tree[rs(i)].lz_qf^=1;
    tree[i].lz_fz=-1,tree[i].lz_qf=0;

}

void build(int l,int r,int i){

    tree[i].l=l,tree[i].r=r,tree[i].lz_qf=0,tree[i].lz_fz=-1;
    if(l==r)
    {
        tree[i].sum_0=tree[i].l_0=tree[i].r_0=tree[i].all_0=!input[l];
        tree[i].sum_1=tree[i].l_1=tree[i].r_1=tree[i].all_1=input[l];
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,ls(i));
    build(mid+1,r,rs(i));
    update(i);

}

void change(int l,int r,int i,int opt){

    if(tree[i].l>=l&&tree[i].r<=r)
    {
        if(opt==0)
        {
            fz0(i);
            tree[i].lz_qf=0,tree[i].lz_fz=opt;
        }
        if(opt==1)
        {
             fz1(i);
             tree[i].lz_qf=0,tree[i].lz_fz=opt;
        }
        if(opt==2)
        {
             qf(i);
             tree[i].lz_qf^=1;
        }
        return ;
    }
    lztage(i);
    if(tree[ls(i)].r>=l) change(l,r,ls(i),opt);
    if(tree[rs(i)].l<=r) change(l,r,rs(i),opt);
    update(i);

}

int search1(int l,int r,int i){

    if(tree[i].l>=l&&tree[i].r<=r) return tree[i].sum_1;
    lztage(i);
    int sum=0;
    if(tree[ls(i)].r>=l) sum+=search1(l,r,ls(i));
    if(tree[rs(i)].l<=r) sum+=search1(l,r,rs(i));
    return sum;

}

void search2(int l,int r,int i){

    if(tree[i].l>=l&&tree[i].r<=r)
    {
        Treetmp[++len_]=tree[i];
//      printf("%d ",tree[i].all_1);
        return ;
    }

    lztage(i);

    if(tree[ls(i)].r>=l) search2(l,r,ls(i));
    if(tree[rs(i)].l<=r) search2(l,r,rs(i)); 

}

int search3(int i,int s){

    if(tree[i].l==tree[i].r) return tree[i].sum_1;

    lztage(i);
    if(tree[ls(i)].r>=s) return search3(ls(i),s);
    if(tree[rs(i)].l<=s) return search3(rs(i),s);

}//debug

int f(){

    int Max=0;
    for(int i=1;i<=len_;i++)
    {
        int nl=Treetmp[i].l_1,j=i;
        while(j<len_&&(Treetmp[j+1].sum_1==(Treetmp[j+1].r-Treetmp[j+1].l+1)))
            nl+=Treetmp[j+1].sum_1,j++;
        Max=_max(Max,_max(Treetmp[i].all_1,nl+Treetmp[j+1].r_1));
    }
    Max=_max(Max,Treetmp[len_].all_1);
    return Max;

}//比较笨的查询方法 

void debug(int n){

    printf("\n***********************\n");
    for(int i=1;i<=n;i++)
        printf("%d ",search3(1,i));
    printf("\n***********************\n");

}

int main(){

    int n,m;
    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++)
        scanf("%d",&input[i]);
    build(1,n,1);

    cout<<endl;
    debug(n);

    while(m--)
    {
        int opt,l,r;
        scanf("%d%d%d",&opt,&l,&r);
        l++,r++;
        if(opt<=2) change(l,r,1,opt),debug(n);
        else
        {
            if(opt==3) printf("%d",search1(l,r,1)),debug(n);
            if(opt==4)
            {
                len_=0;search2(l,r,1);
                printf("%d",f());
                debug(n);
            }
        }
    }

    return 0;

}

感谢


by epicpans @ 2021-04-13 18:45:05

可以把题目发下吗

但一般别指望我,我菜得一批


by LordLaffey @ 2021-04-13 18:51:03

@epicpans P2572一个下标从0开始的长度为n的01序列,m个操作

感谢大佬


by epicpans @ 2021-04-14 21:25:52

@Wmlj__ytm

我说了别指望我呀[大哭][大哭]。。。

我只是个垃圾

但我认识一个大佬,周六去问问他

你应该不急吧

(真对不起,让你失望了)


by LordLaffey @ 2021-04-19 18:22:46

时隔5天回来
@epicpans 拜托大佬了


|