Advertisement
artemgf

Петя и карточки

Dec 22nd, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #pragma once
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #define _USE_MATH_DEFINES
  4. #include <iostream>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <stdio.h>
  11. #include <cmath>
  12. #include <math.h>
  13. #include <queue>
  14. #include <stack>
  15. #include <climits>
  16. #include <deque>
  17. #include <ctime>
  18. #include <iomanip>
  19. #include <bitset>
  20. #include <unordered_map>
  21. #include <unordered_set>
  22. #include <fstream>
  23.  
  24. using namespace std;
  25.  
  26. typedef long long ll;
  27. typedef unsigned long long ull;
  28. typedef unsigned int ui;
  29.  
  30. #define mh() make_heap()
  31. #define poph() pop_heap()
  32. #define pushh() push_heap()
  33. #define sor(n) n.begin(), n.end()
  34. #define rsor(n) n.rbegin(), n.rend()
  35. #define mp make_pair
  36. #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
  37. #define p(T) pair<T,T>
  38. #define toch(x) cout.precision(x), cout.setf(ios::fixed)
  39. #define znac(l) abs(l)/l
  40. #define IOS ios::sync_with_stdio(false)
  41. #define IOSB cin.tie(0), cout.tie(0);
  42. const ll ok = ll(1e9 + 7);
  43. string t[2 * 131072];
  44. void add(int pos, string new_val) {
  45.     pos += 131071;
  46.     t[pos] = new_val;
  47.     for (pos = pos >> 1; pos; pos = pos >> 1)
  48.     {
  49.         string p = t[pos];
  50.         t[pos] =  t[pos << 1]+ t[(pos << 1) + 1];
  51.         if (p == t[pos])
  52.             break;
  53.     }
  54. }
  55.  
  56. void del(int pos) {
  57.     pos += 131071;
  58.     t[pos] = "";
  59.     for (pos = pos >> 1; pos; pos = pos >> 1)
  60.     {
  61.         string p = t[pos];
  62.         t[pos] = t[pos << 1] + t[(pos << 1) + 1];
  63.         if (p == t[pos])
  64.             break;
  65.     }
  66. }
  67.  
  68. string sumotr(ll tl, ll tr, ll pos, ll nl, ll nr)
  69. {
  70.     if (tl == nl && tr == nr)
  71.         return t[pos];
  72.     else
  73.         if (tl > tr)
  74.             return"";
  75.     ll nm = (nl + nr) >> 1;
  76.     string sum = "";
  77.     sum += sumotr(tl, min(nm, tr), pos << 1, nl, nm);
  78.     sum += sumotr(max(nm + 1, tl), tr, (pos << 1) + 1, nm + 1, nr);
  79.     return sum;
  80. }
  81.  
  82. int main()
  83. {
  84.     IOSB;
  85.     IOS;
  86. #ifdef TheCompiler
  87.     files;
  88. #endif
  89.     ll n;
  90.     cin >> n;
  91.     stack<ll>last;
  92.     map<string, ll>z;
  93.     ll k = 1;
  94.     for (int i = 1; i <= n; i++)
  95.     {
  96.         string a;
  97.         cin >> a;
  98.         if (a == "more")
  99.         {
  100.             cin >> a;
  101.             add(k, a);
  102.             z[a] = k;
  103.             k++;
  104.         }
  105.         else
  106.             if (a == "del")
  107.             {
  108.                 cin >> a;
  109.                 if (z.find(a) != z.end()&&z[a] != -1 )
  110.                 {
  111.                     del(z[a]);
  112.                     z[a] = -1;
  113.                 }
  114.                 else
  115.                     cout << "You stupid" << endl;
  116.             }
  117.             else
  118.                 if (a == "chng")
  119.                 {
  120.                     string b;
  121.                     cin >> a >> b;
  122.                     add(z[a], b);
  123.                 }
  124.             else
  125.             {
  126.                 ll t1, t2;
  127.                 cin >> t1 >> t2;
  128.                 cout << sumotr(t1, t2, 1, 1, 131072) << endl;
  129.             }
  130.     }
  131.     return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement