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 <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll = long long;
using ld = long double;
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false)
#define N 1000005
#define M 40000005
#define ALL(x) x.begin(), x.end()
char A[M]; int L[M], R[M], root[N], len[N], ALLOC = 1, cur = 0;
int persist0(char c)
{
A[ALLOC] = c;
return ALLOC++;
}
int persist1(int l, int r)
{
int p = ALLOC++;
L[p] = l, R[p] = r;
return p;
}
int build(int l, int r)
{
if (l == r) return persist0(0);
return persist1(build(l, (l+r)/2), build((l+r)/2+1, r));
}
int upd(int v, int l, int r, int p, char c)
{
if (l == r) return persist0(c);
if (p <= (l+r)/2) return persist1(upd(L[v], l, (l+r)/2, p, c), R[v]);
return persist1(L[v], upd(R[v], (l+r)/2+1, r, p, c));
}
int qry(int v, int l, int r, int p)
{
if (l == r) return A[v];
if (p <= (l+r)/2) return qry(L[v], l, (l+r)/2, p);
return qry(R[v], (l+r)/2+1, r, p);
}
void Init()
{
root[0] = build(1, 1000000);
}
void TypeLetter(char c)
{
++cur; len[cur] = len[cur - 1] + 1;
root[cur] = upd(root[cur-1], 1, 1000000, len[cur - 1], c);
}
void UndoCommands(int u)
{
int f = cur++ - u;
root[cur] = root[f]; len[cur] = len[f];
}
char GetLetter(int k)
{
return qry(root[cur], 1, 1000000, k);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |