无脑线段树
#include<iostream>
using namespace std;
const int N = 1e5+10;
int a[N],b[N];
struct Segment{
int l,r;
int s,s1,s2;
int lz1,lz2;
}tr[N<<2];
void pushdown(int u){
if(tr[u].lz1){
tr[u<<1].lz1 = tr[u<<1|1].lz1 = 1;
tr[u].lz1 = 0;
tr[u<<1].s1 = tr[u<<1].r-tr[u<<1].l+1;
tr[u<<1].s = tr[u<<1].s2;
tr[u<<1|1].s1 = tr[u<<1|1].r-tr[u<<1|1].l+1;
tr[u<<1|1].s = tr[u<<1|1].s2;
}
if(tr[u].lz2){
tr[u<<1].lz2 = tr[u<<1|1].lz2 = 1;
tr[u].lz2 = 0;
tr[u<<1].s2 = tr[u<<1].r-tr[u<<1].l+1;
tr[u<<1].s = tr[u<<1].s1;
tr[u<<1|1].s2 = tr[u<<1|1].r-tr[u<<1|1].l+1;
tr[u<<1|1].s = tr[u<<1|1].s1;
}
}
void pushup(int u){
tr[u].s = tr[u<<1].s + tr[u<<1|1].s;
tr[u].s1 = tr[u<<1].s1 + tr[u<<1|1].s1;
tr[u].s2 = tr[u<<1].s2 + tr[u<<1|1].s2;
}
void build(int u,int l,int r){
tr[u] = {l,r};
if(l==r){
tr[u].s1 = a[l];
tr[u].s2 = b[l];
tr[u].s = a[l]&&b[l];
tr[u].lz1 = tr[u].lz2 = 0;
return;
}
int mid = (l+r)>>1;
build(u<<1,l,mid),build(u<<1|1,mid+1,r);
pushup(u);
}
void modify1(int u,int l,int r){
if(l<=tr[u].l&&tr[u].r<=r){
tr[u].s1 = tr[u].r-tr[u].l+1;
tr[u].s = tr[u].s2;
tr[u].lz1 = 1;
return;
}
pushdown(u);
int mid = tr[u].l+tr[u].r>>1;
if(l<=mid)modify1(u<<1,l,r);
if(r>mid)modify1(u<<1|1,l,r);
pushup(u);
}
void modify2(int u,int l,int r){
if(l<=tr[u].l&&tr[u].r<=r){
tr[u].s2 = tr[u].r-tr[u].l+1;
tr[u].s = tr[u].s1;
tr[u].lz2 = 1;
return;
}
pushdown(u);
int mid = tr[u].l+tr[u].r>>1;
if(l<=mid)modify2(u<<1,l,r);
if(r>mid)modify2(u<<1|1,l,r);
pushup(u);
}
int query(int u,int l,int r){
if(l<=tr[u].l&&tr[u].r<=r){
return tr[u].s;
}
pushdown(u);
int res = 0;
int mid = tr[u].l+tr[u].r>>1;
if(l<=mid)res+=query(u<<1,l,r);
if(r>mid)res+=query(u<<1|1,l,r);
return res;
}
int main()
{
int n,q;cin>>n;
for(int i=1;i<=n;i++){
char c;cin>>c;if(c=='1')a[i] = 1;else a[i] = 0;
}
for(int i=1;i<=n;i++){
char c;cin>>c;if(c=='0')b[i] = 0;else b[i] = 1;
}
build(1,1,n);
cin>>q;
while(q--){
char c;int l,r;cin>>c>>l>>r;
if(c=='A')modify1(1,l,r);
else modify2(1,l,r);
cout<<query(1,1,n)<<"\n";
}
}