#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define for0(i,n) for(int i=0;i<=(int)n;i++)
#define forn(i,n) for(int i=n;i>=1;i--)
#define fo(i,x,y) for(int i=x;i<=(int)y;i++)
#define fr(i,x,y) for(int i=x;i>=(int)y;i--)
#define pb push_back
#define mp make_pair
#define LL long long
const LL Mod=1000*1000*1000+7;
char last;
int OP_NOW;
int letter_par[1000002];
int up[1000002][30];
int height[1000002];
int maxhi=0;
void Init() {}
void TypeLetter(char L) {
OP_NOW++;
letter_par[OP_NOW]=(L-'a');
height[OP_NOW]=height[OP_NOW-1]+1;
maxhi=max(maxhi,height[OP_NOW]);
up[OP_NOW][0]=(OP_NOW-1);
int G=log2(4*maxhi);
for1(i,G)
up[OP_NOW][i]=up[up[OP_NOW][i-1]][i-1];
}
void UndoCommands(int U) {
OP_NOW++;
height[OP_NOW]=height[OP_NOW-U-1];
letter_par[OP_NOW]=letter_par[OP_NOW-U-1];
int G=log2(4*maxhi);
for0(i,G)
up[OP_NOW][i]=up[OP_NOW-U-1][i];
}
char GetLetter(int P) {
int N=height[OP_NOW];
if((P+1)==height[OP_NOW])
{
return (letter_par[OP_NOW]+'a');
}
int pos=OP_NOW;
//cout<<pos<<" "<<up[pos][0]<<" "<<up[pos][1]<<" "<<up[pos][2]<<" "<<up[pos][3]<<endl;
int G=log2(4*maxhi);
fr(i,G,0)
{
//cout<<up[pos][i]<<" "<<height[up[pos][i]]<<endl;
if(height[up[pos][i]]>=(P+1))
{
//cout<<i<<"dddd"<<endl;
pos=up[pos][i];
}
}
return (letter_par[pos]+'a');
}
/*
1000
T a
T b
T d
P 1
*/
Compilation message
scrivener.cpp: In function 'char GetLetter(int)':
scrivener.cpp:52:9: warning: unused variable 'N' [-Wunused-variable]
int N=height[OP_NOW];
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
560 KB |
Output is correct |
4 |
Correct |
2 ms |
560 KB |
Output is correct |
5 |
Correct |
3 ms |
628 KB |
Output is correct |
6 |
Correct |
2 ms |
628 KB |
Output is correct |
7 |
Correct |
3 ms |
692 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
744 KB |
Output is correct |
2 |
Correct |
2 ms |
744 KB |
Output is correct |
3 |
Correct |
3 ms |
744 KB |
Output is correct |
4 |
Correct |
2 ms |
744 KB |
Output is correct |
5 |
Correct |
2 ms |
744 KB |
Output is correct |
6 |
Correct |
2 ms |
744 KB |
Output is correct |
7 |
Correct |
2 ms |
744 KB |
Output is correct |
8 |
Correct |
2 ms |
744 KB |
Output is correct |
9 |
Correct |
3 ms |
744 KB |
Output is correct |
10 |
Correct |
4 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
876 KB |
Output is correct |
3 |
Correct |
5 ms |
1132 KB |
Output is correct |
4 |
Correct |
5 ms |
1156 KB |
Output is correct |
5 |
Correct |
5 ms |
1156 KB |
Output is correct |
6 |
Correct |
4 ms |
1156 KB |
Output is correct |
7 |
Correct |
4 ms |
1156 KB |
Output is correct |
8 |
Correct |
6 ms |
1156 KB |
Output is correct |
9 |
Correct |
7 ms |
1156 KB |
Output is correct |
10 |
Correct |
4 ms |
1156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
822 ms |
90216 KB |
Output is correct |
2 |
Correct |
932 ms |
110168 KB |
Output is correct |
3 |
Correct |
615 ms |
110168 KB |
Output is correct |
4 |
Correct |
573 ms |
114592 KB |
Output is correct |
5 |
Correct |
879 ms |
114592 KB |
Output is correct |
6 |
Correct |
862 ms |
119460 KB |
Output is correct |
7 |
Execution timed out |
1029 ms |
119460 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1096 ms |
119460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |