Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimzize("Ofast,no-stack-protector")
- #include<bits/stdc++.h>
- //#define int long long
- #define quick ios::sync_with_stdio(0);cin.tie(0);
- #define rep(x,a,b) for(int x=a;x<=b;x++)
- #define repd(x,a,b) for(int x=a;x>=b;x--)
- #define lowbit(x) (x&-x)
- #define sz(x) (int)(x.size())
- #define F first
- #define S second
- #define all(x) x.begin(),x.end()
- #define mp make_pair
- #define eb emplace_back
- using namespace std;
- typedef complex<int> P;
- #define X real()
- #define Y imag()
- typedef pair<int,int> pii;
- void debug(){
- cout<<"\n";
- }
- template <class T,class ... U >
- void debug(T a, U ... b){
- cout<<a<<" ",debug(b...);
- }
- const int N=5e4+7;
- const int INF=1e18;
- bitset<N> A;
- bitset<N> C[N];
- int pref[N];
- char a[N];
- bool b[N];
- bool ok[N];
- void solve(){
- int n;
- cin>>n;
- unordered_map<int,int> pos;
- rep(i,1,n){
- cin>>a[i];
- pref[i]=pref[i-1];
- if(a[i]=='1') ++pref[i];
- else --pref[i];
- }
- rep(i,1,n){
- char bi;
- cin>>bi;
- b[i]=(bi-'0');
- ok[i]=true;
- }
- rep(i,1,n){
- int idx=pos[pref[i]];
- C[i]=(C[idx]<<(i-idx));
- A=(A<<1);
- if(a[i]=='1'){
- // increasing
- A|=(C[i-1]<<1);
- }
- else{
- //decreasing
- A^=C[i];
- }
- rep(k,1,n){
- if(i<=k){
- if(b[i]){
- ok[k]&=(pref[i]>0);
- }
- else ok[k]&=(pref[i]<=0);
- }
- else{
- if(b[i]){
- ok[k]&=(A[k]);
- }
- else{
- ok[k]&=(~A[k]);
- }
- }
- }
- C[i][0]=true;
- pos[pref[i]]=i;
- }
- //rep(i,1,n) cout<<b[i];cout<<"\n";
- rep(k,1,n){
- cout<<ok[k];
- }cout<<"\n";
- }
- signed main(){
- quick
- int t;
- cin>>t;
- while(t--) solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement