#include <bits/stdc++.h>
#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;
template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxS = 1e6 + 10;
const int maxT = 5e6 + 10;
struct node
{
int cnt;
node *left, *right;
char c;
node() : cnt(0) {}
node(int cnt, char c) : cnt(cnt), c(c) {}
} f[maxT];
node *pt = &f[0], *pos[maxS];
int ver = 0, idx;
char val;
node* build(int lo, int hi)
{
if (lo == hi)
{
return ++pt;
}
int mid = (lo + hi) / 2;
node *cur = ++pt;
cur->left = build(lo, mid);
cur->right = build(mid + 1, hi);
return cur;
}
void Init()
{
pos[ver] = build(1, 1000000);
}
node *add(node *x, int lo, int hi)
{
if (lo == hi)
{
++pt;
*pt = node(1, val);
return pt;
}
int mid = (lo + hi) / 2;
node *cur = ++pt;
if (x->left->cnt < mid - lo + 1)
{
cur->left = add(x->left, lo, mid);
cur->right = x->right;
}
else
{
cur->left = x->left;
cur->right = add(x->right, mid + 1, hi);
}
cur->cnt = cur->left->cnt + cur->right->cnt;
return cur;
}
void TypeLetter(char L)
{
val = L;
pos[ver + 1] = add(pos[ver], 1, 1000000);
++ver;
}
void UndoCommands(int U)
{
++pt;
*pt = *pos[ver - U];
pos[++ver] = pt;
}
char query(node* x, int lo, int hi)
{
if (lo == hi && lo == idx)
{
return x->c;
}
int mid = (lo + hi) / 2;
if (idx <= mid)
{
return query(x->left, lo, mid);
}
return query(x->right, mid + 1, hi);
}
char GetLetter(int P)
{
idx = ++P;
return query(pos[ver], 1, 1000000);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
156920 KB |
Output is correct |
2 |
Correct |
84 ms |
157048 KB |
Output is correct |
3 |
Correct |
83 ms |
156920 KB |
Output is correct |
4 |
Correct |
84 ms |
156924 KB |
Output is correct |
5 |
Correct |
84 ms |
156924 KB |
Output is correct |
6 |
Correct |
87 ms |
156920 KB |
Output is correct |
7 |
Correct |
86 ms |
157048 KB |
Output is correct |
8 |
Correct |
87 ms |
156936 KB |
Output is correct |
9 |
Correct |
87 ms |
156840 KB |
Output is correct |
10 |
Correct |
84 ms |
156936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
156920 KB |
Output is correct |
2 |
Correct |
85 ms |
156824 KB |
Output is correct |
3 |
Correct |
85 ms |
156884 KB |
Output is correct |
4 |
Correct |
86 ms |
156920 KB |
Output is correct |
5 |
Correct |
85 ms |
156920 KB |
Output is correct |
6 |
Correct |
84 ms |
156920 KB |
Output is correct |
7 |
Correct |
85 ms |
156920 KB |
Output is correct |
8 |
Correct |
84 ms |
156920 KB |
Output is correct |
9 |
Correct |
86 ms |
156920 KB |
Output is correct |
10 |
Correct |
88 ms |
156920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
156920 KB |
Output is correct |
2 |
Correct |
88 ms |
156920 KB |
Output is correct |
3 |
Correct |
86 ms |
156920 KB |
Output is correct |
4 |
Correct |
88 ms |
157048 KB |
Output is correct |
5 |
Correct |
87 ms |
157048 KB |
Output is correct |
6 |
Correct |
88 ms |
157048 KB |
Output is correct |
7 |
Correct |
86 ms |
156920 KB |
Output is correct |
8 |
Correct |
85 ms |
156920 KB |
Output is correct |
9 |
Correct |
86 ms |
156920 KB |
Output is correct |
10 |
Correct |
87 ms |
156920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
143 ms |
158456 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
166 ms |
158456 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |