Advertisement
esraa_syam

^^

Sep 11th, 2023
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define nl "\n"
  4. #define fi first
  5. #define se second
  6. #define pi 3.14159
  7. #define ll long long
  8. #define odd(a)  (a&1)
  9. #define even(a)  !(a&1)
  10. #define Mod 1'000'000'007
  11. #define INF 2'000'000'000 // 2e9
  12. #define sz(x) int(x.size())
  13. #define charToInt(s) (s - '0')
  14. #define ull unsigned long long
  15. #define number_line iota(all(vec) , 1)
  16. #define all(s) s.begin(), s.end()
  17. #define rall(v) v.rbegin() , v.rend()
  18. #define fixed(n) fixed << setprecision(n)
  19. #define Num_of_Digits(n) ((int)log10(n) + 1)
  20. #define to_decimal(bin) stoll(bin, nullptr, 2)
  21. #define Ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  22. #define Floor(n, m) (((n) / (m)) - ((n) % (m) ? 0 : 1))
  23. #define Upper(s) transform(all(s), s.begin(), ::toupper);
  24. #define Lower(s) transform(all(s), s.begin(), ::tolower);
  25. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  26. //  ----- bits-------
  27. #define pcnt(n) __builtin_popcount(n)
  28. #define pcntll(n) __builtin_popcountll(n)
  29. #define clz(n) __builtin_clz(n)    // <---100
  30. #define clzll(n) __builtin_clzll(n)
  31. #define ctz(n) __builtin_ctz(n)  // 0001---->
  32. #define ctzll(n) __builtin_ctzll(n)
  33.  
  34. using namespace std;
  35.  
  36. template<typename T = int>
  37. istream &operator>>(istream &in, vector<T> &v) {
  38.     for (auto &x: v) in >> x;
  39.     return in;
  40. }
  41.  
  42. template<typename T = int>
  43. ostream &operator<<(ostream &out, const vector<T> &v) {
  44.     for (const T &x: v) out << x << " ";
  45.     return out;
  46. }
  47.  
  48. void esraa() {
  49.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  50. #ifndef ONLINE_JUDGE
  51.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  52. #endif
  53. }
  54.  
  55.  
  56.  
  57. void solve() {
  58.     string s;
  59.     cin >> s;
  60.     vector < vector < int > > idx(26);
  61.     for(int i = 0 ; i < sz(s) ; i++){
  62.         idx[s[i]].push_back(i);
  63.     }
  64.     for(int i = 0 ; i < 26 ; i++){
  65.         sort(all(idx[i]));
  66.     }
  67.     int q;
  68.     cin >> q;
  69.     string t = "";
  70.     ll last_valid = 0  , cnt_no = 0;
  71.     deque < int > last;
  72.     while(q--){
  73.         string x;
  74.         cin >> x;
  75.         bool ok = true;
  76.         if(x == "push"){
  77.             char c;
  78.             cin >> c;
  79.             t += c;
  80. //            cout << t << nl;
  81.             if(sz(t) == 0) cout << "YES" << nl;
  82.             else if(sz(t) == 1){
  83.                 if(sz(idx[c]) == 0 or cnt_no > 0) cout << "NO" << nl , ok = false , cnt_no++;
  84.                 else cout << "YES" << nl , last.push_back(idx[c][0]);
  85.             }
  86.             else{
  87.                 if(cnt_no > 0) cout << "NO" << nl , cnt_no++;
  88.                 else{
  89.                     if(last.empty()) last.push_back(-1);
  90.                     auto it = upper_bound(all(idx[c]) , last.back());
  91. //                    cout << *it << nl;
  92. //                    cout << last.back() << " " << c << nl;
  93.                     if(it == idx[c].end()){
  94.                         cnt_no++;
  95.                         cout << "NO" << nl;
  96.                         last.push_back(INF);
  97.                     }else cout << "YES" << nl , last.push_back(*it);
  98. //                    cout << last.back() << nl;
  99.                 }
  100.  
  101.             }
  102.         }else{
  103. //            cout << cnt_no << nl;
  104.             if(cnt_no > 0)  cnt_no--;
  105.             if(cnt_no > 0) cout << "NO" << nl , cnt_no++;
  106.             else cout << "YES" << nl;
  107.             t.pop_back();
  108. //            cout << last.back() << " " << " pop" << nl;
  109.             last.pop_back();
  110.         }
  111.     }
  112. //    for(int i = 0 ; i < sz(s) ; i++){
  113. //        for(auto & c : idx[s[i]]) cout << c << " ";
  114. //        cout << nl;
  115. //    }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. }
  125.  
  126. int main() {
  127.     esraa();
  128.     int t = 1;
  129. //     cin >> t;
  130.     //cin.ignore();
  131.     while (t--)
  132.         solve();
  133.     return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement