#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100000

enum Type{
	F,
	G,
};

struct Info{
	Info(int arg_left,int arg_right){
		left = arg_left;
		right = arg_right;
	}
	int left,right;
};

int N = 1;
int data[4*NUM][2];
char buf[NUM+1];

void init(int first_N){
	while(N < first_N)N *= 2;
}

void update(int update_left,int update_right,int new_value,int node_id,int node_left,int node_right,Type type){
	if(update_right < node_left || update_left > node_right)return;
	else if(update_left <= node_left && update_right >= node_right){
		data[node_id][type] = new_value;
	}else{
		if(data[node_id][type] != -1){
			data[2*node_id+1][type] = data[node_id][type];
			data[2*node_id+2][type] = data[node_id][type];
			data[node_id][type] = -1;
		}
		update(update_left,update_right,new_value,2*node_id+1,node_left,(node_left+node_right)/2,type);
		update(update_left,update_right,new_value,2*node_id+2,(node_left+node_right)/2+1,node_right,type);
	}
}

int getSum(int search_left,int search_right,int node_id,int node_left,int node_right,Type type){
	if(search_right < node_left || search_left > node_right){
		return 0;
	}else{
		if(data[node_id][type] == -1){
			int left = getSum(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2,type);
			int right = getSum(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right,type);
			return left+right;
		}else{
			return (min(search_right,node_right)-max(search_left,node_left)+1)*data[node_id][type];
		}
	}
}

int query(int search_left,int search_right,int node_id,int node_left,int node_right,Type type){
	if(search_right < node_left || search_left > node_right){
		return -1;
	}else if(node_left <= search_left && node_right >= search_right && data[node_id][type] != -1){
		return data[node_id][type];
	}else{
		int left = query(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2,type);
		int right = query(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right,type);
		return max(left,right);
	}
}

int main(){

	int first_N;
	scanf("%d",&first_N);

	init(first_N);

	for(int i = 0; i <= 2*N-2; i++){
		data[i][F] = 0;
		data[i][G] = 0;
	}

	scanf("%s",buf);

	vector<Info> V;

	for(int i = 0; buf[i] != '\0';){
		if(buf[i] == '1'){
			int k = i;
			while(buf[k] != '\0' && buf[k] == '1')k++;
			k--;
			V.push_back(Info(i,k));
			i = k+1;
		}else{
			i += 1;
		}
	}

	for(int i = 0; i < V.size(); i++){
		update(V[i].left,V[i].right,1,0,0,N-1,F);
		update(V[i].left+1,V[i].right,1,0,0,N-1,G);
	}

	int Q;
	scanf("%d",&Q);

	int left,right,value;
	int sum_F,sum_G,tmp;

	for(int loop = 0; loop < Q; loop++){
		scanf("%d %d %d",&left,&right,&value);
		left--;
		right--;

		if(value == 0){

			update(left,right,0,0,0,N-1,F);
			update(left,right,0,0,0,N-1,G);

			if(right == first_N-1){
				//Do nothing
			}else{
				tmp = query(right+1,right+1,0,0,N-1,G);
				if(tmp == 1){
					update(right+1,right+1,0,0,0,N-1,G);
				}
			}

		}else{ //value == 1

			update(left,right,1,0,0,N-1,F);

			if(left > 0){
				tmp = query(left-1,left-1,0,0,N-1,F);
				if(tmp == 0){
					left += 1;
				}
			}else{
				left += 1;
			}

			if(right <= first_N-2){
				if(getSum(right+1,right+1,0,0,N-1,F) == 1){
					right += 1;
				}
			}
			update(left,right,1,0,0,N-1,G);
		}

		sum_F = getSum(0,first_N-1,0,0,N-1,F);
		sum_G = getSum(0,first_N-1,0,0,N-1,G);

		printf("%d\n",sum_F-sum_G);
	}
}



Measured memory_bytes: 5472