#include <cstdio>
#include <cstdint>
const int MAXN = 1000005;
char a[MAXN];
inline int read()
{
int x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9')
{
x = (x << 3) + (x << 1) + (ch - '0');
ch = getchar();
}
return x;
}
inline void readStr(int n)
{
for (int i = 1; i <= n; i++)
{
char c = getchar();
while (c != '0' && c != '1') c = getchar();
a[i] = c;
}
}
inline void writeInt(int x)
{
if (x >= 10) writeInt(x / 10);
putchar('0' + (x % 10));
}
int main()
{
int n = read();
int m = read();
readStr(n);
while (m--)
{
int op = read();
int l = read();
int r = read();
if (op == 0)
{
char* p = a + l;
char* end = a + r + 1;
while (p < end && (reinterpret_cast<uintptr_t>(p) % 8 != 0))
{
*p ^= 1;
p++;
}
while (p + 7 < end)
{
*reinterpret_cast<uint64_t*>(p) ^= 0x0101010101010101;
p += 8;
}
while (p < end)
{
*p ^= 1;
p++;
}
}
else
{
int sum = 0;
char* p = a + l;
char* end = a + r + 1;
while (p < end && (reinterpret_cast<uintptr_t>(p) % 8 != 0))
{
sum += (*p & 1);
p++;
}
while (p + 7 < end)
{
uint64_t chunk = *reinterpret_cast<uint64_t*>(p);
chunk &= 0x0101010101010101;
sum += __builtin_popcountll(chunk);
p += 8;
}
while (p < end)
{
sum += (*p & 1);
p++;
}
writeInt(sum);
putchar('\n');
}
}
return 0;
}