#include using namespace std; using ll = long long; #include using namespace atcoder; struct S { ll sum; ll b0; ll b1; ll a0; ll a1; ll n0; ll n1; }; S op(S a, S b) { S c = S{0, 0, 0, 0, 0, 0, 0}; ll al = a.n0 + a.n1, bl = b.n0 + b.n1; c.sum = a.sum + (a.n0 * a.n1 * bl) + b.sum + (b.n0 * b.n1 * al) + a.a0 * b.b1 + a.a1 * b.b0; c.b0 = a.b0 + (b.b0 + al * b.n0); c.b1 = a.b1 + (b.b1 + al * b.n1); c.a0 = b.a0 + (a.a0 + bl * a.n0); c.a1 = b.a1 + (a.a1 + bl * a.n1); c.n0 = a.n0 + b.n0; c.n1 = a.n1 + b.n1; return c; } S e() { return S{0, 0, 0, 0, 0, 0, 0}; } S one0() { return S{0, 1, 0, 1, 0, 1, 0}; } S one1() { return S{0, 0, 1, 0, 1, 0, 1}; } S one(int a) { return (a ? one1() : one0()); } int main () { int N, Q; cin >> N >> Q; string s; cin >> s; std::vector A(N); for (int i = 0; i < N; i ++) { A[i] = one(s[i] - '0'); } segtree sg(A); while (Q--) { int t; cin >> t; if (t - 1) { int l, r; cin >> l >> r; l --; cout << sg.prod(l, r).sum << endl; } else { int i; cin >> i; i --; s[i] = (s[i] == '0' ? '1' : '0'); sg.set(i, one(s[i] - '0')); } } }