题解 P5057 【[CQOI2006]简单题】

· · 题解

纯树状数组,直接过。

#include<iostream>
#include<cstdio>
using namespace std;
int a[500002],c[500002],n,m,u,v,k,l;
int lb(int x){
    return x&(-x);
}
void ch(int x,int y){
    for(;x<=n;x+=lb(x))c[x]+=y;
}
int cnt(int x){
    int s=0;
    for(;x;x-=lb(x))s+=c[x];
    return s;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        scanf("%d",&k);
        if(k==1){
        scanf("%d%d",&u,&v);
        ch(u,1);
        ch(v+1,-1);
        }
        else{
            scanf("%d",&l);
            printf("%d\n",cnt(l)%2);
        }
    }
}