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>
using namespace std;
const int N=1000050,M=N*16;
int root[M],ls[M],rs[M],tsz,cnt,sz[N];
char ch[M];
void Set(int p,int&c,int ss,int se,int qi,char L){
c=++tsz;ls[c]=ls[p];rs[c]=rs[p];ch[c]=L;
if(ss==se)return;
int mid=ss+se>>1;
if(qi<=mid)Set(ls[p],ls[c],ss,mid,qi,L);
else Set(rs[p],rs[c],mid+1,se,qi,L);
}
char Get(int c,int ss,int se,int qi){
if(ss==se)return ch[c];
int mid=ss+se>>1;
if(qi<=mid)return Get(ls[c],ss,mid,qi);
else return Get(rs[c],mid+1,se,qi);
}
void Init(){}
void TypeLetter(char L){
cnt++;sz[cnt]=sz[cnt-1]+1;root[cnt]=root[cnt-1];
Set(root[cnt],root[cnt],1,N,sz[cnt],L);
}
void UndoCommands(int x){
cnt++;root[cnt]=root[cnt-x-1];
sz[cnt]=sz[cnt-x-1];
}
char GetLetter(int x){
return Get(root[cnt],1,N,x+1);
}
Compilation message (stderr)
scrivener.cpp: In function 'void Set(int, int&, int, int, int, char)':
scrivener.cpp:9:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
9 | int mid=ss+se>>1;
| ~~^~~
scrivener.cpp: In function 'char Get(int, int, int, int)':
scrivener.cpp:15:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
15 | int mid=ss+se>>1;
| ~~^~~
# | 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... |