#include<bits/stdc++.h>
using namespace std;
#define ls (p<<1)
#define rs (p<<1|1)
#define int long long
const int maxn=400020;
char c[maxn];
int tree[maxn],tag[maxn],a[maxn];
void update(int p) {
tree[p]=tree[ls]+tree[rs];
}
void build(int pl,int pr,int p) {
if(pl==pr) {
tree[p]=a[pl];
return;
}
int mid=(pl+pr)>>1;
build(pl,mid,p*2);
build(mid+1,pr,p*2+1);
update(p);
}
void tagdown3(int pl,int pr,int p) {
int mid=(pl+pr)>>1;
if(tag[p]) {
tag[ls]^=tag[p];
tag[rs]^=tag[p];
tree[ls]=mid-pl+1-tree[ls];
tree[rs]=pr-mid-tree[rs];
tag[p]=0;
}
return ;
}
void change3(int L,int R,int pl,int pr,int p) {
if(L<=pl&&pr<=R) {
tag[p]^=1;
tree[p]=pr-pl+1-tree[p];
return;
}
tagdown3(pl,pr,p);
int mid=(pl+pr)>>1;
if(L<=mid) change3(L,R,pl,mid,ls);
if(R>mid) change3(L,R,mid+1,pr,rs);
update(p);
}
int query3(int L,int R,int pl,int pr,int p) {
if(L<=pl&&pr<=R) {
return tree[p];
}
tagdown3(pl,pr,p);
int mid=(pl+pr)>>1;
int ans=0;
if(L<=mid) ans+=query3(L,R,pl,mid,ls);
if(R>mid) ans+=query3(L,R,mid+1,pr,rs);
return ans;
}
signed main() {
int n,m,op,L,R;
cin>>n>>m;
build(1,n,1);
for(int i=1; i<=n; i++) {
cin>>c[i];
}
for(int i=1; i<=n; i++) {
a[i]=c[i]-'0';
}
for(int i=1;i<=n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
while(m--) {
cin>>op>>L>>R;
if(op==0) {
change3(L,R,1,n,1);
} else {
cout<<query3(L,R,1,n,1)<<endl;
}
}
return 0;
}
/*
10 6
1011101001
0 2 4
1 1 5
0 3 7
1 1 10
0 1 4
1 2 6
*/
玄关求调