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 = 1e6 + 1;
struct node {
int val;
node *left, *right;
node() : left(NULL), right(NULL) { };
node(const int &x) : val(x), left(NULL), right(NULL) { };
node(node* l, node* r) : left(l), right(r) { };
};
struct Persistent_Segment_Tree {
node *root;
Persistent_Segment_Tree() : root(NULL) { };
node* upd(node* v, int l, int r, int u, int x) {
if (l == r) return new node(x);
int m = l + r >> 1;
if (u <= m) return new node(upd(v->left, l, m, u, x), v->right);
else return new node(v->left, upd(v->right, m + 1, r, u, x));
}
node* build(node *v, int l, int r) {
if (l == r) return new node;
int m = l + r >> 1;
return new node(build(v->left, l, m), build(v->right, m + 1, r));
}
int qry(node* &v, int l, int r, int u) {
if (l == r) return v->val;
int m = l + r >> 1;
if (u <= m) return qry(v->left, l, m, u);
return qry(v->right, m + 1, r, u);
}
void build() {
root = build(root, 0, N - 1);
}
node* upd(int u, int x) {
return upd(root, 0, N - 1, u, x);
}
int qry(int u) {
return qry(root, 0, N - 1, u);
}
} st[N];
int cur[N];
int t;
void Init() {
st[0].build();
}
void TypeLetter(char L) {
st[t].root = st[t + 1].root = st[t].upd(cur[t]++, L - 'a');
cur[t + 1] = cur[t];
t++;
}
void UndoCommands(int U) {
cur[t] = cur[t + 1] = cur[t - U - 1];
st[t] = st[t + 1] = st[t - U - 1];
t++;
}
char GetLetter(int P) {
return 'a' + st[t].qry(P);
}
Compilation message (stderr)
scrivener.cpp: In member function 'node* Persistent_Segment_Tree::upd(node*, int, int, int, int)':
scrivener.cpp:19:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | int m = l + r >> 1;
| ~~^~~
scrivener.cpp: In member function 'node* Persistent_Segment_Tree::build(node*, int, int)':
scrivener.cpp:25:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
25 | int m = l + r >> 1;
| ~~^~~
scrivener.cpp: In member function 'int Persistent_Segment_Tree::qry(node*&, int, int, int)':
scrivener.cpp:30:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | int m = l + r >> 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... |