이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = (int) 1e6 + 5;
#define mid (bas + son) / 2
int cnt,n = 1000000,c[N];
class tree{ public:
int x;
tree *l,*r;
};
typedef tree* pTree;
void build(pTree root,int bas,int son) {
if (bas == son) {
root -> x = 0;
return;
}
root -> l = new tree;
root -> r = new tree;
build(root -> l,bas,mid);
build(root -> r,mid + 1,son);
root -> x = root -> l -> x + root ->r ->x;
}
pTree update(pTree root,int bas,int son,int wh,int val) {
pTree t = new tree;
if (bas == son && bas == wh) {
t -> x = val;
return t;
}
if (wh <= mid) {
t -> l = update(root -> l,bas,mid,wh,val);
t -> r = root -> r;
}
else {
t -> l = root -> l;
t -> r = update(root -> r,mid + 1,son,wh,val);
}
t -> x = t -> l -> x + t -> r -> x;
return t;
}
int query(pTree root,int bas,int son,int wh) {
if (bas > wh || son < wh) return 0;
if (bas == wh && son == wh) return root -> x;
return query(root -> l,bas,mid,wh) + query(root -> r,mid + 1,son,wh);
}
pTree T[N];
char last;
void Init() {
T[0] = new tree;
build(T[0],1,n);
}
void TypeLetter(char L) {
T[cnt + 1] = update(T[cnt],1,n,c[cnt] + 1,(int) L);
cnt++;
c[cnt] = c[cnt - 1] + 1;
}
void UndoCommands(int U) {
T[cnt + 1] = T[cnt - U];
c[cnt + 1] = c[cnt - U];
cnt++;
}
char GetLetter(int P) {
return (char) query(T[cnt],1,n,P + 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... |