Advertisement
SorahISA

1-ag-lite-text-editor

Apr 10th, 2023
723
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #pragma GCC optimize("Ofast", "unroll-loops")
  2. // #pragma GCC target("avx")
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define int int64_t
  7. #define double __float80
  8. using pii = pair<int, int>;
  9. template <typename T> using Prior = std::priority_queue<T>;
  10. template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
  11.  
  12. // #define X first
  13. // #define Y second
  14. #define eb emplace_back
  15. #define ef emplace_front
  16. #define ee emplace
  17. #define pb pop_back
  18. #define pf pop_front
  19. #define ALL(x) begin(x), end(x)
  20. #define RALL(x) rbegin(x), rend(x)
  21. #define SZ(x) ((int)(x).size())
  22.  
  23. #define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
  24. template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
  25. template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
  26.  
  27. template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
  28. template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
  29.  
  30. void solve() {
  31.     string S; getline(cin, S);
  32.     int C; cin >> C;
  33.    
  34.     vector<string> buf;
  35.     for (int q = 1; q <= C; ++q) {
  36.         string op; cin >> op;
  37.        
  38.         if (op == "COPY") {
  39.             int L, R; cin >> L >> R, --L, --R;
  40.             buf.eb(S.substr(L, R-L+1));
  41.         }
  42.        
  43.         if (op == "CUT") {
  44.             int L, R; cin >> L >> R, --L, --R;
  45.             buf.eb(S.substr(L, R-L+1));
  46.             S = S.substr(0, L) + S.substr(R+1);
  47.         }
  48.        
  49.         if (op == "PASTE") {
  50.             int pos; cin >> pos, --pos;
  51.             S = S.substr(0, pos) + buf.back() + S.substr(pos);
  52.             if (SZ(buf) > 1) buf.pb();
  53.         }
  54.     }
  55.     cout << S << "\n";
  56. }
  57.  
  58. int32_t main() {
  59.     fastIO();
  60.    
  61.     int t = 1; // cin >> t;
  62.     for (int _ = 1; _ <= t; ++_) {
  63.         solve();
  64.     }
  65.    
  66.     return 0;
  67. }
  68.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement