#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline void chmin(T &l,T r){l=min(l,r);}
template <typename T>inline void chmax(T &l,T r){l=max(l,r);}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int n;
    string x;
    int q;
    cin>>n>>x>>q;
    map<int,int> lr;
    REP(i,n){
        if(x[i]=='0')continue;
        if(i==0||x[i-1]=='0'){
            lr[i+1]=i;
        }
        else{
            int bg=lr[i];
            lr.erase(i);
            lr[i+1]=bg;
        }
        
    }
    REP(qq,q){
        int l,r,b;
        cin>>l>>r>>b;
        l--;
        if(b==1){
            while(true){
                auto it=lr.upper_bound(l);
                if(it==lr.end()||r<it->se){
                    if(lr.count(l)){
                        lr[r]=lr[l];
                        lr.erase(l);       
                    }
                    else lr[r]=l;
                    break;
                }
                else{
                    //       cout<<" "<<it->se<< " "<<it->fi<<endl;
                    chmin(l,it->se);
                    chmax(r,it->fi);
                    lr.erase(it->fi);
                    //cout<<" "<<r<<endl;
                }
            }
        }
        else{
            while(true){
                auto it=lr.upper_bound(l);
                if(it==lr.end()||r<=it->se){
                    break;
                }
                else{
                    if(it->se<l)lr[l]=lr[it->fi];
                    if(r<it->fi)lr[it->fi]=r;
                    else{
                        lr.erase(it->fi);
                    }
                }

            }
        }
        //        for(auto &it:lr)cout<<it.se<<" "<<it.fi<<endl;
        cout<<lr.size()<<endl;
    }
    return 0;
}