# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
591569 | stevancv | Crayfish scrivener (IOI12_scrivener) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "scrivener.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e6;
int st[20 * N], lc[20 * N], rc[20 * N], root[N], tsz;
void Add(int& node, int pnode, int l, int r, int x, int y) {
node = ++tsz;
if (l == r) {st[node] = y; return; }
lc[node] = lc[pnode]; rc[node] = rc[pnode];
int mid = l + r >> 1;
if (x <= mid) Add(lc[node], lc[pnode], l, mid, x, y);
else Add(rc[node], rc[pnode], mid + 1, r, x, y);
}
int Get(int node, int l, int r, int p) {
if (l == r) return st[node];
int mid = l + r >> 1;
if (p <= mid) return Get(lc[node], l, mid, p);
else return Get(rc[node], mid + 1, r, p);
}
int sz[N], ind;
void TypeLetter(char c) {
ind += 1;
sz[ind] = sz[ind - 1] + 1;
int br = c - 'a' + 1;
Add(root[ind], root[ind - 1], 1, N, sz[ind], br);
}
void UndoCommands(int u) {
ind += 1;
u += 1;
cout << ind << sp << ind - u << en;
sz[ind] = sz[ind - u];
root[ind] = root[ind - u];
}
char GetLetter(int p) {
p += 1;
int x = Get(root[ind], 1, N, p);
return (char)(x + 'a' - 1);
}
void Init() {}