Advertisement
yuhung94

J.cpp

Feb 14th, 2023
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #pragma GCC optimzize("Ofast,no-stack-protector")
  2. #include<bits/stdc++.h>
  3. //#define int long long
  4. #define quick ios::sync_with_stdio(0);cin.tie(0);
  5. #define rep(x,a,b) for(int x=a;x<=b;x++)
  6. #define repd(x,a,b) for(int x=a;x>=b;x--)
  7. #define lowbit(x) (x&-x)
  8. #define sz(x) (int)(x.size())
  9. #define F first
  10. #define S second
  11. #define all(x) x.begin(),x.end()
  12. #define mp make_pair
  13. #define eb emplace_back
  14. using namespace std;
  15. typedef complex<int> P;
  16. #define X real()
  17. #define Y imag()
  18. typedef pair<int,int> pii;
  19. void debug(){
  20.     cout<<"\n";
  21. }
  22. template <class T,class ... U >
  23. void debug(T a, U ... b){
  24.     cout<<a<<" ",debug(b...);
  25. }
  26. const int N=5e4+7;
  27. const int INF=1e18;
  28. bitset<N> A;
  29. bitset<N> C[N];
  30. int pref[N];
  31. char a[N];
  32. bool b[N];
  33. bool ok[N];
  34. void solve(){
  35.     int n;
  36.     cin>>n;
  37.     unordered_map<int,int> pos;
  38.     rep(i,1,n){
  39.         cin>>a[i];
  40.         pref[i]=pref[i-1];
  41.         if(a[i]=='1') ++pref[i];
  42.         else --pref[i];
  43.     }
  44.     rep(i,1,n){
  45.         char bi;
  46.         cin>>bi;
  47.         b[i]=(bi-'0');
  48.         ok[i]=true;
  49.     }
  50.     rep(i,1,n){
  51.         int idx=pos[pref[i]];
  52.         C[i]=(C[idx]<<(i-idx));
  53.         A=(A<<1);
  54.         if(a[i]=='1'){
  55.             // increasing
  56.             A|=(C[i-1]<<1);
  57.         }
  58.         else{
  59.             //decreasing
  60.             A^=C[i];
  61.         }
  62.         rep(k,1,n){
  63.             if(i<=k){
  64.                 if(b[i]){
  65.                     ok[k]&=(pref[i]>0);
  66.                 }
  67.                 else ok[k]&=(pref[i]<=0);
  68.             }
  69.             else{
  70.                 if(b[i]){
  71.                     ok[k]&=(A[k]);
  72.                 }  
  73.                 else{
  74.                     ok[k]&=(~A[k]);
  75.                 }
  76.             }
  77.         }
  78.         C[i][0]=true;
  79.         pos[pref[i]]=i;
  80.     }
  81.     //rep(i,1,n) cout<<b[i];cout<<"\n";
  82.     rep(k,1,n){
  83.         cout<<ok[k];
  84.     }cout<<"\n";
  85.  
  86. }
  87. signed main(){
  88.     quick
  89.     int t;
  90.     cin>>t;
  91.     while(t--) solve();
  92.  
  93.  
  94.     return 0;
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement