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<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 1000010
#define MAXL 22
int trie[MAXN][27], anc[MAXN][MAXL], dub[MAXN];
vector<int> op;
int timer = 0;
void Init() {
timer = 1;
op.pb(1);
}
void TypeLetter(char L) {
int c = L-'a'+1, cur = op.back();
if(trie[cur][c] == 0) {
trie[cur][c] = ++timer;
anc[timer][0] = cur;
dub[timer] = dub[cur] + 1;
for(int i = 1; i < MAXL; i++) anc[timer][i] = anc[anc[timer][i-1]][i-1];
}
op.pb(trie[cur][c]);
}
void UndoCommands(int U) {
op.pb(op[sz(op)-1-U]);
}
char GetLetter(int P) {
int cur = op.back();
P = dub[cur] - 1 - P;
for(int k = MAXL-1; k >= 0; k--) {
if((1<<k) <= P) {
cur = anc[cur][k];
P -= (1<<k);
}
}
int par = anc[cur][0];
for(int i = 1; i < 27; i++) {
if(trie[par][i] == cur) return ('a'+i-1);
}
}
Compilation message (stderr)
scrivener.cpp: In function 'char GetLetter(int)':
scrivener.cpp:56:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |