zoukankan      html  css  js  c++  java
  • [TJOI2009] 开关

    话说我怎么点开了这么个沙雕题

    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 1000005;
    
    int val[N],tag[N],n,m,t1,t2,t3,t4;
    
    void pushup(int p)
    {
        val[p]=val[p*2]+val[p*2+1];
    }
    void pushdown(int p,int l,int r)
    {
        if(tag[p])
        {
            tag[p*2]^=1;
            tag[p*2+1]^=1;
            val[p*2]=(l+r)/2-l+1-val[p*2];
            val[p*2+1]=r-(l+r)/2-val[p*2+1];
            tag[p]^=1;
        }
    }
    
    void modify(int p,int l,int r,int ql,int qr)
    {
        if(l>qr || r<ql) return;
        if(l>=ql && r<=qr)
        {
            val[p]=(r-l+1)-val[p];
            tag[p]^=1;
        }
        else
        {
            pushdown(p,l,r);
            modify(p*2,l,(l+r)/2,ql,qr);
            modify(p*2+1,(l+r)/2+1,r,ql,qr);
            pushup(p);
        }
    }
    
    int query(int p,int l,int r,int ql,int qr)
    {
        if(l>qr || r<ql) return 0;
        if(l>=ql && r<=qr) return val[p];
        else
        {
            pushdown(p,l,r);
            return query(p*2,l,(l+r)/2,ql,qr) + query(p*2+1,(l+r)/2+1,r,ql,qr);
        }
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin>>n>>m;
        for(int i=1; i<=m; i++)
        {
            cin>>t1>>t2>>t3;
            if(t1==0)
            {
                modify(1,1,n,t2,t3);
            }
            else
            {
                cout<<query(1,1,n,t2,t3)<<endl;
            }
        }
    }
    
  • 相关阅读:
    1033.采药1
    G——胜利大逃亡 (BFS)
    POJ 3278 Catch That Cow
    C
    11.17 dfs poj1979 Red and Black
    11.11反思
    kmp笔记
    dfs bfs
    1113
    python 类方法
  • 原文地址:https://www.cnblogs.com/mollnn/p/11764392.html
Copyright © 2011-2022 走看看