#include <bits/stdc++.h>
using namespace std;
struct node
{
int v, l, r;
char c;
};
int all, ver;
int root[1000005];
node seg[30000000];
int build(int l, int r)
{
int now = ++all;
if(l == r) return now;
int mid = (l+r)>>1;
int L = build(l, mid), R = build(mid+1, r);
seg[now] = {0, L, R};
return now;
}
void Init() {
root[0] = build(1, 1000000);
}
int update(int idx, int l, int r, int p, char c) {
if(!(l <= p && p <= r)) return idx;
int now = ++all;
if(l == r)
{
seg[now].v = 1;
seg[now].c = c;
return now;
}
int mid = (l+r)>>1;
int L = update(seg[idx].l, l, mid, p, c), R = update(seg[idx].r, mid+1, r, p, c);
seg[now].l = L, seg[now].r = R, seg[now].v = seg[L].v+seg[R].v;
return now;
}
void TypeLetter(char L) {
ver++;
root[ver] = update(root[ver-1], 1, 1000000, seg[root[ver-1]].v+1, L);
}
void UndoCommands(int U) {
ver++;
root[ver] = root[ver-U-1];
}
char query(int idx, int l, int r, int p)
{
if(l == r) return seg[idx].c;
int mid = (l+r)>>1;
return (p <= mid) ? query(seg[idx].l, l, mid, p) : query(seg[idx].r, mid+1, r, p);
}
char GetLetter(int P) {
return query(root[ver], 1, 1000000, P+1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
31616 KB |
Output is correct |
2 |
Correct |
27 ms |
31616 KB |
Output is correct |
3 |
Correct |
28 ms |
31736 KB |
Output is correct |
4 |
Correct |
27 ms |
31608 KB |
Output is correct |
5 |
Correct |
27 ms |
31616 KB |
Output is correct |
6 |
Correct |
28 ms |
31608 KB |
Output is correct |
7 |
Correct |
27 ms |
31616 KB |
Output is correct |
8 |
Correct |
28 ms |
31616 KB |
Output is correct |
9 |
Correct |
27 ms |
31608 KB |
Output is correct |
10 |
Correct |
28 ms |
31616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
31616 KB |
Output is correct |
2 |
Correct |
27 ms |
31616 KB |
Output is correct |
3 |
Correct |
28 ms |
31720 KB |
Output is correct |
4 |
Correct |
28 ms |
31608 KB |
Output is correct |
5 |
Correct |
30 ms |
31616 KB |
Output is correct |
6 |
Correct |
27 ms |
31608 KB |
Output is correct |
7 |
Correct |
29 ms |
31744 KB |
Output is correct |
8 |
Correct |
32 ms |
31740 KB |
Output is correct |
9 |
Correct |
27 ms |
31608 KB |
Output is correct |
10 |
Correct |
27 ms |
31616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
32120 KB |
Output is correct |
2 |
Correct |
33 ms |
32120 KB |
Output is correct |
3 |
Correct |
30 ms |
32248 KB |
Output is correct |
4 |
Correct |
29 ms |
32640 KB |
Output is correct |
5 |
Correct |
31 ms |
32248 KB |
Output is correct |
6 |
Correct |
30 ms |
32888 KB |
Output is correct |
7 |
Correct |
30 ms |
32892 KB |
Output is correct |
8 |
Correct |
30 ms |
32504 KB |
Output is correct |
9 |
Correct |
30 ms |
32632 KB |
Output is correct |
10 |
Correct |
29 ms |
32256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
421 ms |
225784 KB |
Output is correct |
2 |
Correct |
450 ms |
245496 KB |
Output is correct |
3 |
Correct |
451 ms |
240892 KB |
Output is correct |
4 |
Correct |
473 ms |
195832 KB |
Output is correct |
5 |
Correct |
500 ms |
212856 KB |
Output is correct |
6 |
Correct |
457 ms |
262144 KB |
Output is correct |
7 |
Correct |
445 ms |
139048 KB |
Output is correct |
8 |
Correct |
460 ms |
199416 KB |
Output is correct |
9 |
Runtime error |
419 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
490 ms |
196296 KB |
Output is correct |
2 |
Correct |
528 ms |
175736 KB |
Output is correct |
3 |
Correct |
452 ms |
190244 KB |
Output is correct |
4 |
Correct |
481 ms |
147440 KB |
Output is correct |
5 |
Correct |
420 ms |
205688 KB |
Output is correct |
6 |
Correct |
420 ms |
194680 KB |
Output is correct |
7 |
Correct |
455 ms |
206412 KB |
Output is correct |
8 |
Correct |
481 ms |
109816 KB |
Output is correct |
9 |
Correct |
538 ms |
179320 KB |
Output is correct |
10 |
Correct |
372 ms |
200824 KB |
Output is correct |