Submission #157766

#TimeUsernameProblemLanguageResultExecution timeMemory
157766davitmargCrayfish scrivener (IOI12_scrivener)C++17
100 / 100
839 ms94968 KiB
/*DavitMarg*/ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <set> #include <queue> #include <iomanip> #include <bitset> #include <stack> #include <cassert> #include <iterator> #include <ctype.h> #include <fstream> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(), v.end() using namespace std; const int N = 1000000; int k, n, up[N + 10][30], d[N + 10], ind[N + 10], v = 1, timer; char a[N + 10]; void addNode(int p, char x) { v = ++n; a[v] = x; d[v] = d[p] + 1; up[v][0] = p; for (int i = 1; i <= k; i++) up[v][i] = up[up[v][i - 1]][i - 1]; } char get(int v, int cnt) { if (cnt == d[v]) return a[v]; for (int i = k; i >= 0; i--) { int p = up[v][i]; if (d[p] > cnt) v = p; } return a[up[v][0]]; } void Init() { while ((1 << k) <= N) k++; } void TypeLetter(char x) { addNode(v, x); ind[++timer] = v; } char GetLetter(int pos) { return get(v, pos + 1); } void UndoCommands(int cnt) { v = ind[timer + 1] = ind[timer - cnt]; timer++; } #ifdef death int main() { Init(); TypeLetter('a'); TypeLetter('b'); TypeLetter('c'); cout << GetLetter(2) << endl; TypeLetter('d'); UndoCommands(2); UndoCommands(1); cout << GetLetter(2) << endl; return 0; } #endif /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...