Submission #17134

#TimeUsernameProblemLanguageResultExecution timeMemory
17134erdemkirazCrayfish scrivener (IOI12_scrivener)C++98
0 / 100
1000 ms169684 KiB
#include <bits/stdc++.h> using namespace std; #define type(x) __typeof((x).begin()) #define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++) typedef long long ll; typedef pair < int, int > ii; const int inf = 1e9 + 333; const ll linf = 1e18 + inf; const int N = 1e6 + 5; const int LOG = 21; void Init() {} int x = 0; int op[N], lca[LOG][N], sum[LOG][N]; void TypeLetter(char c) { op[++x] = c; lca[0][x] = x - 1; sum[0][x] = 1; for(int i = 1; i < LOG; i++) { lca[i][x] = lca[i - 1][lca[i - 1][x]]; sum[i][x] = sum[i - 1][lca[i - 1][x]] + sum[i - 1][x]; } } void UndoCommands(int k) { x++; lca[0][x] = x - 1 - k; sum[0][x] = 0; for(int i = 1; i < LOG; i++) { lca[i][x] = lca[i - 1][lca[i - 1][x]]; sum[i][x] = sum[i - 1][lca[i - 1][x]] + sum[i - 1][x]; } } char GetLetter(int p) { int sz = sum[LOG - 1][x - 1]; int k = sz - p - 1; int x1 = x - 1; for(int i = LOG - 1; i >= 0; i--) { if(sum[i][x1] <= k) { //printf("i = %d nx = %d\n", i, lca[i][x1]); k -= sum[i][x1]; x1 = lca[i][x1]; } } //printf("x1 = %d\n", x1); return op[x1]; }
#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...