#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;
typedef long long ll;
struct node{
int git[27], par[23], ne, der;
} x[N];
int n, m, k, yer[N];
void Init(){
}
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 < 22; 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 = 21; 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
scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:24:18: warning: array subscript has type 'char' [-Wchar-subscripts]
if(x[node].git[c] != 0)
^
scrivener.cpp:25:27: warning: array subscript has type 'char' [-Wchar-subscripts]
yer[++m] = x[node].git[c];
^
scrivener.cpp:27:16: warning: array subscript has type 'char' [-Wchar-subscripts]
x[node].git[c] = ++k;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
612 KB |
Output is correct |
3 |
Correct |
20 ms |
768 KB |
Output is correct |
4 |
Correct |
5 ms |
896 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
4 ms |
1152 KB |
Output is correct |
8 |
Correct |
4 ms |
896 KB |
Output is correct |
9 |
Correct |
3 ms |
1024 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
811 ms |
120332 KB |
Output is correct |
2 |
Execution timed out |
1079 ms |
132316 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
889 ms |
101916 KB |
Output is correct |
2 |
Correct |
999 ms |
89328 KB |
Output is correct |
3 |
Correct |
490 ms |
102092 KB |
Output is correct |
4 |
Correct |
450 ms |
75000 KB |
Output is correct |
5 |
Correct |
616 ms |
112504 KB |
Output is correct |
6 |
Correct |
570 ms |
104696 KB |
Output is correct |
7 |
Correct |
615 ms |
112076 KB |
Output is correct |
8 |
Correct |
769 ms |
55288 KB |
Output is correct |
9 |
Execution timed out |
1042 ms |
98048 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |