# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
910045 | Macker | Crayfish scrivener (IOI12_scrivener) | C++17 | 0 ms | 0 KiB |
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 <stdlib.h>
#include <stdio.h>
#include <assert.h>
#define inbuf_len 1 << 16
#define outbuf_len 1 << 16
void Init();
void TypeLetter(char L);
void UndoCommands(int U);
char GetLetter(int P);
int main() {
Init();
int cmd_num;
auto tmp = scanf("%d", &cmd_num);
assert(tmp == 1);
int i;
for (i = 0; i < cmd_num; i++) {
char cmd;
tmp = scanf(" %c", &cmd);
assert(tmp == 1);
if (cmd == 'T') {
char letter;
tmp = scanf(" %c", &letter);
assert(tmp == 1);
TypeLetter(letter);
}
else if (cmd == 'U') {
int number;
tmp = scanf("%d", &number);
assert(tmp == 1);
UndoCommands(number);
}
else if (cmd == 'P') {
int index;
char letter;
tmp = scanf("%d", &index);
assert(tmp == 1);
letter = GetLetter(index);
printf("%c\n", letter);
}
}
puts("Let's test for cheating!!");
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
struct node {
char c;
array<node*, 22> par;
int len;
};
typedef node* pnode;
pnode cur;
vector<pnode> undo;
void Init() {
cur = new node();
cur->len = -1;
undo.push_back(cur);
}
void TypeLetter(char L) {
pnode tmp = new node();
tmp->par[0] = cur;
for (int i = 1; i < 22; i++) {
if(tmp->par[i - 1] == NULL) break;
tmp->par[i] = tmp->par[i - 1]->par[i - 1];
}
tmp->c = L;
tmp->len = cur->len + 1;
cur = tmp;
undo.push_back(cur);
}
void UndoCommands(int U) {
pnode tmp = undo[undo.size() - U - 1];
cur = tmp;
undo.push_back(cur);
}
char GetLetter(int P) {
pnode tmp = cur;
int x = tmp->len - P;
for (int i = 0; i < 22; i++) {
if(x & (1 << i)){
tmp = tmp->par[i];
}
}
return tmp->c;
}