이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int n = 1e6;
struct node {
char c;
node *l, *r;
node(char c) : c(c), l(0), r(0) {}
node(node *l, node *r) : c(0), l(l), r(r) {}
};
node *build(int b=0, int e=n-1)
{
if (b == e) return new node(0);
int m = (b+e)/2;
return new node(build(b, m), build(m+1, e));
}
node *update(int i, char c, node *p, int b=0, int e=n-1)
{
if (b==e) return new node(c);
int m = (b+e)/2;
if (i <= m)
return new node(update(i, c, p->l, b, m), p->r);
else
return new node(p->l, update(i, c, p->r, m+1, e));
}
char get(int i, node *p, int b=0, int e=n-1)
{
if (b == e) return p->c;
int m = (b+e)/2;
if (i <= m)
return get(i, p->l, b, m);
else
return get(i, p->r, m+1, e);
}
const int V = 1e6+1;
int vc = 0;
int len[V];
node *ptr[V];
void Init() {
//printf("Init()\n");
len[0] = 0;
ptr[0] = build();
}
void TypeLetter(char L) {
//printf("TypeLetter(%c)\n", L);
++vc;
len[vc] = len[vc-1]+1;
ptr[vc] = update(len[vc-1], L, ptr[vc-1]);
}
void UndoCommands(int U)
{
//printf("UndoCommands(%d)\n", U);
U = min(U, vc);
++vc;
len[vc] = len[vc-U-1];
ptr[vc] = ptr[vc-U-1];
}
char GetLetter(int P)
{
char ans = get(P, ptr[vc]);
//printf("GetLetter(%d) = %c\n", P, ans);
return ans;
}
# | 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... |