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 <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
const int N=1000050;
const int M=20*N;
int ls[M],rs[M],root[N],tsz;
char ch[M];
void Set(int p, int &c, int ss, int se, int qi, char s)
{
c=++tsz;ls[c]=ls[p];rs[c]=rs[p];ch[c]=s;
if(ss==se) return;
int mid=ss+se>>1;
if(qi<=mid) Set(ls[p],ls[c],ss,mid,qi,s);
else Set(rs[p],rs[c],mid+1,se,qi,s);
}
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(){}
int cnt=0,sz[N];
void TypeLetter(char s)
{
cnt++;sz[cnt]=sz[cnt-1]+1;
root[cnt]=root[cnt-1];
Set(root[cnt],root[cnt],1,N,sz[cnt],s);
}
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:13:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=ss+se>>1;
~~^~~
scrivener.cpp: In function 'char Get(int, int, int, int)':
scrivener.cpp:20:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
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... |