P5057 [CQOI2006]简单题

传送门

可以看成每一次区间+1,最后询问某个位置上数的奇偶性,树状数组即可

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=1e5+5;
int c[N],n,m,op,l,r,pos;
inline void add(R int x,R int y){for(;x<=n;x+=x&-x)c[x]+=y;}
inline int query(R int x){R int res=0;for(;x;x-=x&-x)res+=c[x];return res;}
int main(){
//  freopen("testdata.in","r",stdin);
    n=read(),m=read();
    while(m--){
        op=read();
        if(op==1)l=read(),r=read(),add(l,1),add(r+1,-1);
        else pos=read(),putchar((query(pos)&1)?'1':'0'),putchar('\n');
    }return 0;
}

猜你喜欢

转载自www.cnblogs.com/bztMinamoto/p/10082283.html