이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include <bits/stdc++.h>
//
//using namespace std;
//const int N=1e6+5;
//int a[N];
//char b[N];
//int c[N];
//char s[N];
//int cnt;
//int k=0;
//
//
//void Init() {}
//
//void TypeLetter(char L) {
// a[k]=1;
// b[k]=L;
// k++;
//}
//
//void UndoCommands(int U) {
// a[k]=2;
// c[k]=U;
// k++;
//}
//
//char GetLetter(int P) {
// if(cnt==0)
// {
// int j=0;
// k--;
// while(k>=0)
// {
// if(a[k]==1)
// {
// s[j]=b[k];
// j++;
// }
// else if(a[k]==2)
// {
// k=k-c[k];
// }
// else
// {
// cout<<k<<endl;
// assert(0);
// }
// k--;
// }
// reverse(s,s+j);
// }
// cnt=1;
// return s[P];
//}
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+55;
int trie[N*4][26];
char letter[N];
int p[N][22];
int a[N];
int l[N];
int node;
int cnt=1;
int k;
void Init()
{
node=cnt++;
memset(trie,-1,sizeof trie);
}
void TypeLetter(char L)
{
int c=L-'a';
int temp=node;
if(trie[node][c]==-1)
trie[node][c]=cnt++;
letter[node]=c;
node=trie[node][c];
a[k]=node;
l[k]=l[k-1]+1;
p[node][0]=temp;
for(int i=1;i<=21;i++)
p[node][i]=p[p[node][i-1]][i-1];
k++;
}
void UndoCommands(int U)
{
node=a[k-U];
l[k]=l[k-U];
a[k]=node;
k++;
}
char GetLetter(int P)
{
P=l[k-1]-P;
for(int i=21;i>=0;i--)
{
if(P&(1<<i))
P=p[node][i];
}
return letter[P];
}
# | 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... |