이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
struct node {
char c;
node *left, *right;
node() : left(NULL), right(NULL) { };
node(const char &x) : c(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, const char &x) {
if (l == r) return new node(x);
if (!v) v = new node;
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));
}
char qry(node* &v, int l, int r, int u) {
if (l == r) return v->c;
int m = l + r >> 1;
if (u <= m) return qry(v->left, l, m, u);
return qry(v->right, m + 1, r, u);
}
} st[N];
int cur[N];
int t;
void Init() {
}
void TypeLetter(char L) {
st[t].root = st[t + 1].root = st[t].upd(st[t].root, 0, N - 1, cur[t]++, L);
cur[t + 1] = cur[t];
t++;
}
void UndoCommands(int U) {
cur[t] = cur[t + 1] = cur[t - U - 1];
st[t].root = st[t + 1].root = st[t - U - 1].root;
t++;
}
char GetLetter(int P) {
return st[t].qry(st[t].root, 0, N - 1, P);
}
컴파일 시 표준 에러 (stderr) 메시지
scrivener.cpp: In member function 'node* Persistent_Segment_Tree::upd(node*, int, int, int, const char&)':
scrivener.cpp:20:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | int m = l + r >> 1;
| ~~^~~
scrivener.cpp: In member function 'char Persistent_Segment_Tree::qry(node*&, int, int, int)':
scrivener.cpp:26:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | 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... |