hpnq

PIVO

Sep 11th, 2022
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define loop(x, n) for(ll i = x; i < n; i++ )
  4. #define pb push_back
  5. #define MOD ll(1e9+7)
  6. #define all(x) x.begin(), x.end()
  7. #define f first
  8. #define s second
  9. #define DEBUG 1
  10. typedef long long ll;
  11. using namespace std;
  12. int next(int n, int k){
  13.     return (n+k)%26;
  14. }
  15.  
  16. ///
  17. struct Node{
  18.     int prior, size = 1;
  19.     int value;
  20.     Node *l = 0, *r = 0;
  21.     Node(int _key) {value = _key, prior = rand();}
  22. };
  23. ///
  24.  
  25. typedef pair<Node*, Node*> Pair;
  26.  
  27. int size(Node *v){return v ? v->size : 0;}
  28. void upd(Node *v){v->size = size(v->l) + size(v->r) + 1;}
  29.  
  30.  
  31. Node *merge(Node *l, Node *r){
  32.     if(!l) return r;
  33.     if(!r) return l;
  34.     if(l->prior > r->prior){
  35.         l->r = merge(l->r, r);
  36.         upd(l);
  37.         return l;
  38.     }else{
  39.         r->l = merge(l, r->l);
  40.         upd(l);
  41.         return r;
  42.     }
  43. }
  44.  
  45. Pair split(Node *p, int k){
  46.     if(!p) return {0, 0};
  47.     if(size(p->l) + 1 <= k){
  48.         Pair q = split(p->r, k - size(p->l) - 1);
  49.         p->l = q.second;
  50.         upd(p);
  51.         return {q.first, p};
  52.     }else{
  53.         Pair q = split(p->l, k);
  54.         p->l = q.second;
  55.         upd(p);
  56.         return {q.first, p};
  57.     }
  58. }
  59.  
  60. //Node *root = 0;
  61. void insert(Node *root, int x) {
  62.     Pair q= split(root, x);
  63.     Node *t = new Node(x);
  64. //    cout << q.f << " " << q.s << "\n";
  65.     root = merge(q.first, merge(t, q.second ));
  66. //    cout <<root->size <<"\n";
  67. }
  68. ///////
  69. ///////
  70.  
  71.  
  72. Node* ctrlx (Node *root, int l, int r) {
  73.     Pair q1 = split(root, r);
  74.     Pair q2 = split(q1.first, l);
  75.     root = merge(q2.first, q1.second);
  76.     return q2.second;
  77. }
  78.  
  79. void ctrlv (Node *root, Node *v, int k) {
  80.     Pair q = split(root, k);
  81.     root = merge(q.first, merge(v, q.second));
  82. }
  83.  
  84.  
  85. ///////
  86. ///////
  87.  
  88. vector<Node*> abc(26);
  89.  
  90. void solve(){
  91.     int n, m;
  92.     cin >> n >> m;
  93.     string a;
  94.     cin >> a;
  95.     ///построить дд /// nlogn
  96. //    cout << abc[0];
  97.     loop(0, n){
  98. //        cout << abc[a[i]-'a'] <<" ";
  99.  
  100.         insert(abc[a[i]-'a'], i);
  101.         cout << abc[a[i]-'a'] <<"\n";
  102.     }
  103.     loop(0, 1){
  104. //        cout << abc[i]->size;
  105.     }
  106.  
  107.     /*
  108.     loop(0, m){
  109.         int q;
  110.         cin >> q;
  111.         if(q == 1){
  112.             //next
  113.             int r, l, k;
  114.             cin >> l >> r >> k;
  115.             Node *v;
  116.             loop(0, 26){
  117.                 v = ctrlx(abc[i], l, r);
  118.                 ctrlv(abc[(i+1)%26], v, l);
  119.  
  120.             }
  121.  
  122.         }else{
  123.             // f(l, r)
  124.             int l, r;
  125.             cin >> l >> r;
  126.             loop(0, 26){
  127.                 Pair qr = split(abc[i], r);
  128.                 Pair ql = split(qr.first, l);
  129.                 cout << ql.first;
  130.             }
  131.  
  132.         }
  133.     }
  134.      */
  135. }
  136.  
  137. int main() {
  138. #ifdef DEBUG
  139.     freopen("text.txt", "r", stdin);
  140.     cout <<"DEBUG" <<"\n";
  141. #else
  142. #endif
  143. //    int t;
  144. //    cin >> t;
  145. //    loop(0, t) {
  146. //        solve();
  147. ////    cout<< solve_all("ananas");
  148. //
  149. //    }
  150.     solve();
  151. //    int n;
  152. //    cin >> n;
  153. //    cout << n;
  154.     return 0;
  155.  
  156.  
  157. }
Add Comment
Please, Sign In to add comment