1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| #include<bits/stdc++.h> using namespace std;
inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();} return x*f; } struct Segtree{ struct Node{ int l,r,val; }tree[2000010]; void pushup(int p){ tree[p].val=tree[p<<1].val+tree[p<<1|1].val; } void build(int p,int l,int r){ tree[p].l=l,tree[p].r=r; if(l==r)return; int mid=l+r>>1; build(p<<1,l,mid); build(p<<1|1,mid+1,r); } void modify(int p,int loc,int val){ if(tree[p].l==tree[p].r){tree[p].val+=val;return;} int mid=tree[p].l+tree[p].r>>1; if(loc<=mid)modify(p<<1,loc,val); else modify(p<<1|1,loc,val); pushup(p); } void equal(int p,int loc,int val){ if(tree[p].l==tree[p].r){tree[p].val=val;return;} int mid=tree[p].l+tree[p].r>>1; if(loc<=mid)equal(p<<1,loc,val); else equal(p<<1|1,loc,val); pushup(p); } int query(int p,int L,int R){ if(L<=tree[p].l&&tree[p].r<=R)return tree[p].val; int mid=tree[p].l+tree[p].r>>1,ans=0; if(L<=mid)ans+=query(p<<1,L,R); if(mid<R)ans+=query(p<<1|1,L,R); return ans; } }tree[2]; char s[500010];int a[500010]; int main(){ int n=read(),q=read(); for(int i=1;i<=n;i++)cin>>s[i]; for(int i=1;i<=n;i++)a[i]=s[i]-48; tree[1].build(1,0,n+10),tree[0].build(1,0,n+10); for(int i=2;i<=n;i++)if(a[i]==a[i-1])tree[1].equal(1,i,1); for(int i=1;i<=q;i++){ int op=read(),l=read(),r=read(); if(op==1){ tree[0].modify(1,l,1),tree[0].modify(1,r+1,-1); int p1=(tree[0].query(1,0,l-1)%2+a[l-1])%2, p2=(tree[0].query(1,0,l)%2+a[l])%2, p3=(tree[0].query(1,0,r)%2+a[r])%2, p4=(tree[0].query(1,0,r+1)%2+a[r+1])%2; if(l>1){ if(p1!=p2)tree[1].equal(1,l,0); else tree[1].equal(1,l,1); } if(r<n){ if(p3!=p4)tree[1].equal(1,r+1,0); else tree[1].equal(1,r+1,1); } } else{ if(l==r)puts("Yes"); else if(tree[1].query(1,l+1,r))puts("No"); else puts("Yes"); } } return 0; }
|