zoukankan      html  css  js  c++  java
  • AC日记——妖梦斩木棒 洛谷 P3797

    妖梦斩木棒

    思路:

      略坑爹;

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    #define maxn 200005
    #define maxm maxn<<2
    int n,m,L[maxm],R[maxm],mid[maxm],dis[maxm];
    bool xx[maxm],ll[maxm],rr[maxm];
    struct AnsType {
        int dis;
        bool l,r,x;
    };
    inline void in(int &now)
    {
        char Cget=getchar();now=0;
        while(Cget>'9'||Cget<'0')Cget=getchar();
        while(Cget>='0'&&Cget<='9')
        {
            now=now*10+Cget-'0';
            Cget=getchar();
        }
    }
    void updata(int now)
    {
        xx[now]=xx[now<<1]&xx[now<<1|1];
        dis[now]=dis[now<<1]+dis[now<<1|1];
        if(rr[now<<1]&&ll[now<<1|1]&&!xx[now<<1]&&!xx[now<<1|1]) dis[now]++;
        ll[now]=xx[now<<1]?ll[now<<1|1]:ll[now<<1];
        rr[now]=xx[now<<1|1]?rr[now<<1]:rr[now<<1|1];
    }
    struct AnsType node(AnsType a,AnsType b)
    {
        AnsType res;
        res.x=a.x&b.x;
        res.l=a.x?b.l:a.l;
        res.r=b.x?a.r:b.r;
        res.dis=a.dis+b.dis;
        if(a.r&&b.l&&!a.x&&!b.x) res.dis++;
        return res;
    }
    void build(int now,int l,int r)
    {
        L[now]=l,R[now]=r;
        if(l==r)
        {
            if(l==1) rr[now]=1;
            else if(r==n) ll[now]=1;
            else xx[now]=1,ll[now]=1,rr[now]=1;
            return;
        }
        mid[now]=l+r>>1;
        build(now<<1,l,mid[now]);
        build(now<<1|1,mid[now]+1,r);
        updata(now);
    }
    void updata(int now,int to,int t)
    {
        if(L[now]==R[now])
        {
            ll[now]=rr[now]=xx[now]=0;
            if(t==0) xx[now]=1,ll[now]=1,rr[now]=1;
            if(t==1) ll[now]=1;
            if(t==2) rr[now]=1;
            return ;
        }
        if(to<=mid[now]) updata(now<<1,to,t);
        else updata(now<<1|1,to,t);
        updata(now);
    }
    AnsType query(int now,int l,int r)
    {
        if(L[now]==l&&R[now]==r) return (AnsType){dis[now],ll[now],rr[now],xx[now]};
        if(r<=mid[now]) return query(now<<1,l,r);
        else if(l>mid[now]) return query(now<<1|1,l,r);
        else return node(query(now<<1,l,mid[now]),query(now<<1|1,mid[now]+1,r));
    }
    int main()
    {
        in(n),in(m),build(1,1,n);
        int op,l,r,x;char ch[4];
        while(m--)
        {
            in(op);
            if(op==1)
            {
                in(x),scanf("%s",ch);
                if(ch[0]=='X') ch[0]=0;
                else if(ch[0]==')') ch[0]=1;
                else ch[0]=2;
                updata(1,x,ch[0]);
            }
            else
            {
                in(l),in(r);
                AnsType res=query(1,l,r);
                printf("%d
    ",res.dis);
            }
        }
        return 0;
    }
  • 相关阅读:
    Git编译安装
    ES集群
    索引、分片以及副本的数量和大小原则:
    初识ELK
    zabbix自定义监控项没权限读取文件问题
    Zabbix的图形界面中文变成□□问题
    logrotate
    rsync
    Linux下的mail指令
    nohup
  • 原文地址:https://www.cnblogs.com/IUUUUUUUskyyy/p/6979175.html
Copyright © 2011-2022 走看看