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 st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1100005
using namespace std;
typedef long long ll;
struct node{
int git[26], par[23], ne, der;
} x[N];
int n, m, k, yer[N], lg[N];
void Init(){
for(int i = 20; i >= 1; i--){
for(int j = (1<<i); j > (1<<(i - 1)); j--){
lg[j] = i;
// cout << j << " " << i << endl;
}
}
lg[0] = 1;
lg[1] = 1;
}
void TypeLetter(char c){
int node = yer[m];
c -= 'a';
if(x[node].git[c] != 0)
yer[++m] = x[node].git[c];
else{
x[node].git[c] = ++k;
x[k].par[0] = node;
x[k].ne = c;
x[k].der = x[node].der + 1;
// cout << node << " ->" << k << endl;
yer[++m] = k;
for(int i = 1; i < lg[x[k].der]; i++){
if(x[k].par[i - 1] == 0)
break;
x[k].par[i] = x[x[k].par[i - 1]].par[i - 1];
}
}
}
void UndoCommands(int y){
yer[m + 1] = yer[m - y];
m++;
}
char GetLetter(int y){
int node = yer[m];
y = x[node].der - (y + 1);
// cout << node << " " << y << " inci harfi bul, en son " << (char)(x[node].ne + 'a') << " var. " << x[node].der << " uzunlugunda" << endl;
for(int i = lg[y]; i >= 0; i--){
if((1<<i) <= y){
y -= (1<<i);
node = x[node].par[i];
}
}
// cout << node << endl;
return x[node].ne + 'a';
}
// int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// Init();
// TypeLetter('a');
// TypeLetter('b');
// cout << GetLetter(1) << endl;
// TypeLetter('d');
// UndoCommands(2);
// UndoCommands(1);
// cout << GetLetter(2) << endl;
// TypeLetter('e');
// UndoCommands(1);
// UndoCommands(5);
// TypeLetter('c');
// cout << GetLetter(2) << endl;
// UndoCommands(2);
// cout << GetLetter(2) << endl;
// return 0;
// }
Compilation message (stderr)
scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:32:18: warning: array subscript has type 'char' [-Wchar-subscripts]
if(x[node].git[c] != 0)
^
scrivener.cpp:33:27: warning: array subscript has type 'char' [-Wchar-subscripts]
yer[++m] = x[node].git[c];
^
scrivener.cpp:35:16: warning: array subscript has type 'char' [-Wchar-subscripts]
x[node].git[c] = ++k;
^
# | 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... |