• P2253 好一个一中腰鼓!


    题面。。

    我也是一中的。。但这个一中是高中。。人家初中就开始学线段树了我是不是有点弱。。

    #include<stdio.h>
    #include<iostream>
    using namespace std;
    const int MaxN(20004);
    struct Node
    {
        int L,R,Mid;
        int Lf,Rf,len;
    }Tree[MaxN*4];
    inline void pushup(int rt)
    {
        Tree[rt].L=Tree[rt<<1].L;
        Tree[rt].R=Tree[rt<<1|1].R;
        Tree[rt].Lf=Tree[rt<<1].Lf;
        Tree[rt].Rf=Tree[rt<<1|1].Rf;
        Tree[rt].Mid=max(Tree[rt<<1].R,Tree[rt<<1].Mid);
        Tree[rt].Mid=max(Tree[rt].Mid,Tree[rt<<1|1].L);
        Tree[rt].Mid=max(Tree[rt].Mid,Tree[rt<<1|1].Mid);
        if(Tree[rt<<1].Rf!=Tree[rt<<1|1].Lf)
        {
            Tree[rt].Mid=max(Tree[rt<<1].R+Tree[rt<<1|1].L,Tree[rt].Mid);
            if(Tree[rt<<1].L==Tree[rt<<1].len)
                Tree[rt].L+=Tree[rt<<1|1].L;
            if(Tree[rt<<1|1].R==Tree[rt<<1|1].len)
                Tree[rt].R+=Tree[rt<<1].R;
        }
        return;
    }
    void Build(int rt,int l,int r)
    {
        Tree[rt].len=r-l+1;
        if(l==r)
        {
            Tree[rt].L=Tree[rt].R=Tree[rt].Mid=1;
            Tree[rt].Lf=Tree[rt].Rf=0;
            return;
        }
        int m=(l+r)>>1;
        Build(rt<<1,l,m);
        Build(rt<<1|1,m+1,r);
        pushup(rt);
        return;
    }
    void Update(int rt,int l,int r,int k)
    {
        if(l==r)
        {
            Tree[rt].Lf=Tree[rt].Rf=(Tree[rt].Rf+1)%2;
            return;
        }
        int m=(l+r)>>1;
        if(k<=m)
            Update(rt<<1,l,m,k);
        else
            Update(rt<<1|1,m+1,r,k);
        pushup(rt);
        return;
    }
    int main()
    {
        int N,M,i,x;
        scanf("%d%d",&N,&M);
        Build(1,1,N);
        for(i=1;i<=M;i++)
        {
            scanf("%d",&x);
            Update(1,1,N,x);
            printf("%d
    ",Tree[1].Mid);
        }
        return 0;
    }
    

      哦对了再附上暴力代码。。因为数据太水了。。O(n*n)完全没压力。。

    #include <cstdio>
    bool a[20005];
    int n,m,x;
    int check() {//计算函数,虽然存在大量重复,但是本人懒得优化(毕竟数据那么水)
        int cans=1,ans=1;
        for(int i=2;i<=n;++i) { // 最大子段和
            if(a[i]!=a[i-1]) cans++;
            if(ans<cans) ans=cans;
            if(a[i]==a[i-1]) cans=1;
        }
        return ans;
    }
    int main() {
        scanf("%d %d",&n,&m);
        for(int i=1;i<=m;++i) {//暴力模拟不解释
            scanf("%d",&x);
            a[x]=!a[x];     //改变状态
            printf("%d
    ",check());//输出
        }
        return 0;
    }
    

      这tm暴力。。又短又好理解。。

  • 相关阅读:
    2019-7-3-WPF-使用-Composition-API-做高性能渲染
    2019-7-3-WPF-使用-Composition-API-做高性能渲染
    2018-8-10-win10-uwp-禁止编译器优化代码
    2018-8-10-win10-uwp-禁止编译器优化代码
    2018-2-13-wpf-如何使用-Magick.NET-播放-gif-图片
    2018-2-13-wpf-如何使用-Magick.NET-播放-gif-图片
    2019-8-31-Developing-Universal-Windows-Apps-开发UWA应用-问答
    2019-8-31-Developing-Universal-Windows-Apps-开发UWA应用-问答
    2019-3-1-WPF-从零开始开发-dotnet-Remoting-程序
    busybox
  • 原文地址:https://www.cnblogs.com/hahaha2124652975/p/11206588.html
Copyright © 2020-2023  润新知