이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const int LOG = 22;
int cur = 1 , nodeInd , root[MAXN] , seg[MAXN * LOG] , lc[MAXN * LOG] , rc[MAXN * LOG];
char ans[MAXN];
void build(int id = 0 , int l = 0 , int r = MAXN){
if(r - l == 1) return;
int mid = l + r >> 1;
lc[id] = ++nodeInd;
rc[id] = ++nodeInd;
build(lc[id] , l , mid);
build(rc[id] , mid , r);
}
int modify(int x , int cid , int l = 0 , int r = MAXN){
int id = ++nodeInd;
seg[id] = seg[cid]; lc[id] = lc[cid]; rc[id] = rc[cid];
if(r - l == 1){
seg[id] = 1;
return id;
}
int mid = l + r >> 1;
if(x < mid) lc[id] = modify(x , lc[id] , l , mid);
else rc[id] = modify(x , rc[id] , mid , r);
seg[id] = seg[lc[id]] + seg[rc[id]];
return id;
}
int get(int x , int id , int l = 0 , int r = MAXN){
if(r - l == 1) return l;
int mid = l + r >> 1;
if(seg[lc[id]] >= x) return get(x , lc[id] , l , mid);
return get(x - seg[lc[id]] , rc[id] , mid , r);
}
void Init() {
build();
return;
}
void TypeLetter(char L) {
ans[cur] = L;
root[cur] = modify(cur , root[cur - 1]);
// cout << cur << ' ' << root[cur] << ' ' << seg[root[cur]] << endl;
cur++;
}
void UndoCommands(int U) {
root[cur] = root[cur - U - 1];
// cout << cur << ' ' << root[cur] << endl;
cur++;
}
char GetLetter(int P) {
int res = get(P + 1 , root[cur - 1]);
// cout << cur << ' ' << P << ' ' << res << endl;
return ans[res];
}
컴파일 시 표준 에러 (stderr) 메시지
scrivener.cpp: In function 'void build(int, int, int)':
scrivener.cpp:12:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
12 | int mid = l + r >> 1;
| ~~^~~
scrivener.cpp: In function 'int modify(int, int, int, int)':
scrivener.cpp:26:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | int mid = l + r >> 1;
| ~~^~~
scrivener.cpp: In function 'int get(int, int, int, int)':
scrivener.cpp:35:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int mid = 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... |