zoukankan      html  css  js  c++  java
  • P5057 [CQOI2006]简单题(线段树)

    果然简单题,5分钟紫题++

    代码

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    int tag[100100<<2],n,m;
    void pushdown(int o){
        if(tag[o]){
            tag[o<<1]^=1;
            tag[o<<1|1]^=1;
            tag[o]=0;
        }
    }
    void update(int L,int R,int l,int r,int o){
        if(L<=l&&r<=R){
            tag[o]^=1;
            return;
        }
        pushdown(o);
        int mid=(l+r)>>1;
        if(L<=mid)
            update(L,R,l,mid,o<<1);
        if(R>mid)
            update(L,R,mid+1,r,o<<1|1);
    }
    int query(int L,int R,int pos,int o){
        if(L==R){
            return tag[o];
        }
        pushdown(o);
        int mid=(L+R)>>1;
        if(pos<=mid)
            return query(L,mid,pos,o<<1);
        else
            return query(mid+1,R,pos,o<<1|1);
    }
    int main(){
        scanf("%d %d",&n,&m);
        for(int i=1;i<=m;i++){
            int opt;
            scanf("%d",&opt);
            if(opt==1){
                int l,r;
                scanf("%d %d",&l,&r);
                update(l,r,1,n,1);
            }
            else{
                int pos;
                scanf("%d",&pos);
                printf("%d
    ",query(1,n,pos,1));
            }
        }
        return 0;
    }
    
  • 相关阅读:
    仓储模式Repository
    jwt测试
    net core webapi jwt
    net core发布到iis遇到的困难
    新的目标
    L9-2.安装mysql数据库
    L9-1-安装Apache
    L8_2
    Linux 08
    Linux 07 故障恢复
  • 原文地址:https://www.cnblogs.com/dreagonm/p/10134047.html
Copyright © 2011-2022 走看看