Ankit_132

B

Jun 12th, 2023
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define ff     first
  9. #define ss     second
  10. #define pb     push_back
  11. #define ppb    pop_back
  12.  
  13.  
  14. int main()
  15. {
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(NULL);
  18.     cout.tie(NULL);
  19.    
  20.     _test
  21.     {
  22.         int n;
  23.         cin>>n;
  24.  
  25.         vector<int> a(n);
  26.         for(auto &e: a)
  27.             cin>>e;
  28.  
  29.         string ans = "";
  30.         vector<int> x;
  31.  
  32.         int ok = 0;
  33.  
  34.         for(auto e: a)
  35.         {
  36.             if(!ans.size())
  37.             {
  38.                 ans += '1';
  39.                 x.pb(a[0]);
  40.                 continue;
  41.             }
  42.  
  43.             if(e >= x.back() && !ok)
  44.             {
  45.                 x.pb(e);
  46.                 ans += '1';
  47.             }
  48.             else if(!ok && e<=x.front())
  49.             {
  50.                 ok = 1;
  51.                 x.pb(e);
  52.                 ans += '1';
  53.             }
  54.             else if(ok && e>=x.back() && e<=x.front())
  55.             {
  56.                 ok = 1;
  57.                 x.pb(e);
  58.                 ans += '1';
  59.             }
  60.             else
  61.                 ans += '0';
  62.         }
  63.  
  64.         cout<<ans<<"\n";
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment