이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
Tran The Bao
CTL - Da Lat
Cay ngay cay dem nhung deo duoc cong nhan
*/
const int N = 1e6 + 5;
struct Node {
int c, h, nxt[26], p[20];
Node() { c = 0; h = 0; memset(nxt, 0, sizeof nxt); memset(p, 0, sizeof p); }
};
int cnt = 0, cmd = 0, a[N];
Node trie[N];
int add(int pos, int c) {
if (trie[pos].nxt[c]) return trie[pos].nxt[c];
trie[pos].nxt[c] = ++cnt;
trie[cnt].c = c;
trie[cnt].h = trie[pos].h + 1;
trie[cnt].p[0] = pos;
FOR(i, 1, 19) trie[cnt].p[i] = trie[trie[cnt].p[i - 1]].p[i - 1];
return cnt;
}
int getc(int pos, int h) {
int diff = trie[pos].h - 1 - h;
FOR(i, 0, 19)
if (diff & (1 << i))
pos = trie[pos].p[i];
return trie[pos].c;
}
void Init() {}
void TypeLetter(char L) {
++cmd;
a[cmd] = add(a[cmd - 1], L - 'a');
}
void UndoCommands(int U) {
++cmd;
a[cmd] = a[cmd - 1 - U];
}
char GetLetter(int P) {
return getc(a[cmd], P) + 'a';
}
/*
14
T a
T b
P 1
T d
U 2
U 1
P 2
T e
U 1
U 5
T c
P 2
U 2
P 2
*/
컴파일 시 표준 에러 (stderr) 메시지
scrivener.cpp: In function 'int add(int, int)':
scrivener.cpp:25:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
25 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
| ^
scrivener.cpp:50:5: note: in expansion of macro 'FOR'
50 | FOR(i, 1, 19) trie[cnt].p[i] = trie[trie[cnt].p[i - 1]].p[i - 1];
| ^~~
scrivener.cpp: In function 'int getc(int, int)':
scrivener.cpp:25:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
25 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
| ^
scrivener.cpp:55:5: note: in expansion of macro 'FOR'
55 | FOR(i, 0, 19)
| ^~~
# | 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... |