# ARC 071 E - TrBBnsformBBtion ( Ad hoc )

E: TrBBnsformBBtion - AtCoder Regular Contest 071 | AtCoder

1. 將 'A' 換成 "BB"
2. 將 'B' 換成 "AA"
3. 將 "AAA" 換成 ""
4. 將 "BBB" 換成 ""

1≤|S|,|T|≤1e5
S,T は文字A,Bからなる。
1≤q≤1e5
1≤ai≤bi≤|S|
1≤ci≤di≤|T|

O( N + Q )

```#include <bits/stdc++.h>
using namespace std;

const int MAXL = ( int ) 1e5 + 1;

string S, T;
int sapfx[ MAXL ], sbpfx[ MAXL ];
int tapfx[ MAXL ], tbpfx[ MAXL ];

signed main(){
ios::sync_with_stdio( 0 );
cin >> S >> T;
for( int i = 0; i < S.size(); ++i ){
sapfx[ i + 1 ] = sapfx[ i ] + ( S[ i ] == 'A' );
sbpfx[ i + 1 ] = sbpfx[ i ] + ( S[ i ] == 'B' );
}
for( int i = 0; i < T.size(); ++i ){
tapfx[ i + 1 ] = tapfx[ i ] + ( T[ i ] == 'A' );
tbpfx[ i + 1 ] = tbpfx[ i ] + ( T[ i ] == 'B' );
}
int Q; cin >> Q;
for( int qi = 0; qi < Q; ++qi ){
int slb, srb, tlb, trb;
cin >> slb >> srb >> tlb >> trb;
--slb, --tlb; // [ lb, rb )
int sa = sapfx[ srb ] - sapfx[ slb ];
int sb = sbpfx[ srb ] - sbpfx[ slb ];
int ta = tapfx[ trb ] - tapfx[ tlb ];
int tb = tbpfx[ trb ] - tbpfx[ tlb ];
int x = sa * 2 + sb;
int y = ta * 2 + tb;
if( x % 3 == y % 3 ){
cout << "YES\n";
} else{
cout << "NO\n";
}
}
return 0;
}
```