#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

set<pii> init(string s) {
    s += '0';
    int prev = 0;
    set<pii> ret;

    // 1 ?£?????????£?§?¶???£?????£?????\???????????£?????\???¨?£???? set ?£?????\???\?£?????£????
    for(size_t i=0; i<s.length(); i++) {
        if(s[i-1] == '1' && s[i] == '0') ret.insert(pii(prev, i-1));
        if(s[i-1] == '0' && s[i] == '1') prev = i;
    }
    return ret;
}

int main() {
    int n, q; cin >> n;
    string s; cin >> s;

    set<pii> range = init(s);
    range.insert(pii(-1e9, -1e9));
    range.insert(pii( 1e9,  1e9));
    cin >> q;
    for(int i=0; i<q; i++) {
        int l, r, b; cin >> l >> r >> b;
        l--; r--;

        // ?\?????§?????£???? l ?£?????¨?¶???£?????£?????£???????????\???§?£?????\?????£???§?£?????£?????\???????????£?????\?????£????
        auto it = range.upper_bound(pii(l,0)); it--;
        int x = (*it).first, y = (*it).second;

        // ?????¢?\?????£?????\???????????£?????£?????£???¨?£?????£?????\???????????£?????¨?¢???¨?????£?????£?????£?????£????
        if(x <= l && r <= y) {
            if(b == 0) {
                range.erase(it);
                if(x <= l-1) range.insert(pii(x, l-1));
                if(r+1 <= y) range.insert(pii(r+1, y));
            }
        }
        // ?????¢?\?????£?????\???????????£?????£?????£???¨?£?????£?????\???????????£?????¨?¢???¨?????£?????£?????£???? (4 ?£?????£?????\?????¨?????????§?£?????£?????£????)
        // -> ?£?????£???¨?£?????£?????\???????????£?????????¢?\?????£?????\???????????£?????¨?¢???¨?????£?????£?????£?????£????
        // -> ?£?????£???¨?£?????£?????\???????????£?????????¢?\?????£?????\???????????£?????\???????????????¨?£?????¨?¢???¨?????£?????£?????£?????£????
        // -> ?£?????£???¨?£?????£?????\???????????£?????????¢?\?????£?????\???????????£?????\???????????????¨?£?????¨?¢???¨?????£?????£?????£?????£????
        // -> ?????¢?\?????£?????£?????£???¨?£?????£???¨?£?????£???¨?£?????£?????\???????????£?????????\?£?????£?????£?????£???? (1 ?£?????????´?????°?£?????£?????£???¨?£?????£???????°???£?????£?????£?????£?????£?????£?????£???°?£?????£?????£?????£????)
        else {
            auto it2 = range.lower_bound(pii(l,0)); it2--;
            if(b == 0) {
                while((*it2).first <= r) {
                    x = (*it2).first, y = (*it2).second;
                    bool ok = false;
                    // ?\???????????????¨
                    if(x <= l && l <= y) {
                        if(x <= l-1) range.insert(pii(x, l-1));
                        ok = true;
                    }
                    // ?\???????????????¨
                    if(x <= r && r <= y) {
                        if(r+1 <= y) range.insert(pii(r+1, y));
                        ok = true;
                    }
                    // ?????¢?\?????£?????\???????????£?????¨?¢???¨????
                    if((l <= x && y <= r) || ok) {
                        it2 = range.erase(it2);
                    }
                    else it2++;
                }
            }
            else {
                int L = l, R = r;
                while(1) {
                    x = (*it2).first, y = (*it2).second;
                    // ?£?????£?????£?????£?????£?????£?????£???§?£?????£?????£?????£?????£???¨?£?????\?????£?????£?????£?????£????
                    bool b1 = (x <= L && L <= y);
                    bool b2 = (x <= R && R <= y);
                    bool b3 = (L <= x && y <= R);
                    bool b4 = (L - 1 == y);
                    bool b5 = (R + 1 == x);
                    if(b1 || b2 || b3 || b4 || b5) {
                        it2 = range.erase(it2);
                        L = min(L, x);
                        R = max(R, y);
                    }
                    else {
                        if((*it2).first <= r) it2++;
                        else break;
                    }
                }
                range.insert(pii(L, R));
            }
        }
        cout << range.size() - 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 4252