이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 P()
{
#if 0
for (int i = 0; i < len[cur]; ++i) printf("%c", qry(root[cur], 0, 1000000, i));
puts("");
#endif
}
void Init()
{
root[0] = build(0, 1000000);
P();
}
void TypeLetter(char c)
{
++cur; len[cur] = len[cur - 1] + 1;
root[cur] = upd(root[cur-1], 0, 1000000, len[cur - 1], c);
P();
}
void UndoCommands(int u)
{
int f = cur++ - u;
root[cur] = root[f]; len[cur] = len[f];
P();
}
char GetLetter(int k)
{
P();
return qry(root[cur], 0, 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... |