Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #define _CRT_SECURE_NO_WARNINGS
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- #include <iomanip>
- #include <bitset>
- #include <unordered_map>
- #include <unordered_set>
- #include <fstream>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- #define mh() make_heap()
- #define poph() pop_heap()
- #define pushh() push_heap()
- #define sor(n) n.begin(), n.end()
- #define rsor(n) n.rbegin(), n.rend()
- #define mp make_pair
- #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
- #define p(T) pair<T,T>
- #define toch(x) cout.precision(x), cout.setf(ios::fixed)
- #define znac(l) abs(l)/l
- #define IOS ios::sync_with_stdio(false)
- #define IOSB cin.tie(0), cout.tie(0);
- const ll ok = ll(1e9 + 7);
- string t[2 * 131072];
- void add(int pos, string new_val) {
- pos += 131071;
- t[pos] = new_val;
- for (pos = pos >> 1; pos; pos = pos >> 1)
- {
- string p = t[pos];
- t[pos] = t[pos << 1]+ t[(pos << 1) + 1];
- if (p == t[pos])
- break;
- }
- }
- void del(int pos) {
- pos += 131071;
- t[pos] = "";
- for (pos = pos >> 1; pos; pos = pos >> 1)
- {
- string p = t[pos];
- t[pos] = t[pos << 1] + t[(pos << 1) + 1];
- if (p == t[pos])
- break;
- }
- }
- string sumotr(ll tl, ll tr, ll pos, ll nl, ll nr)
- {
- if (tl == nl && tr == nr)
- return t[pos];
- else
- if (tl > tr)
- return"";
- ll nm = (nl + nr) >> 1;
- string sum = "";
- sum += sumotr(tl, min(nm, tr), pos << 1, nl, nm);
- sum += sumotr(max(nm + 1, tl), tr, (pos << 1) + 1, nm + 1, nr);
- return sum;
- }
- int main()
- {
- IOSB;
- IOS;
- #ifdef TheCompiler
- files;
- #endif
- ll n;
- cin >> n;
- stack<ll>last;
- map<string, ll>z;
- ll k = 1;
- for (int i = 1; i <= n; i++)
- {
- string a;
- cin >> a;
- if (a == "more")
- {
- cin >> a;
- add(k, a);
- z[a] = k;
- k++;
- }
- else
- if (a == "del")
- {
- cin >> a;
- if (z.find(a) != z.end()&&z[a] != -1 )
- {
- del(z[a]);
- z[a] = -1;
- }
- else
- cout << "You stupid" << endl;
- }
- else
- if (a == "chng")
- {
- string b;
- cin >> a >> b;
- add(z[a], b);
- }
- else
- {
- ll t1, t2;
- cin >> t1 >> t2;
- cout << sumotr(t1, t2, 1, 1, 131072) << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement