이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
struct Trie{
struct Node{
int child[26];
int digit;
int parent;
Node(){digit = parent = -1; memset(child, -1, sizeof child);}
};
int n;
vector<Node> a;
Trie(){
a.push_back(Node());
}
void add_child(int &x){
x = a.size();
a.push_back(Node());
}
void add(string s){
int id= 0;
for(char c: s){
int digit = c - 'a';
if (a[id].child[digit] == -1) add_child(a[id].child[digit]);
a[a[id].child[digit]].parent = id;
id = a[id].child[digit];
a[id].digit = digit;
}
}
void add(int &cur, int digit){
if (a[cur].child[digit] == -1) add_child(a[cur].child[digit]);
a[a[cur].child[digit]].parent = cur;
cur = a[cur].child[digit];
a[cur].digit = digit;
}
int get_digit(int cur){
return a[cur].digit;
}
};
Trie tri;
int cur;
vector<int> pos;
void Init() {
cur = 0;
pos.push_back(0);
}
void TypeLetter(char L) {
int digit = L - 'a';
tri.add(cur, digit);
pos.push_back(cur);
}
void UndoCommands(int U) {
cur = pos[pos.size() - U - 1];
pos.push_back(cur);
}
char GetLetter(int P) {
int tmp = cur;
string x;
while(tmp > 0){
x.push_back('a' + tri.get_digit(tmp));
tmp = tri.a[tmp].parent;
}
reverse(ALL(x));
// cout << x << "\n";
return x[P];
}
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("input.inp", "r", stdin);
// Init();
// int q; cin >> q;
// while(q--){
// char type; cin >> type;
// if (type == 'T'){
// char cur; cin >> cur;
// TypeLetter(cur);
// }
// else if (type == 'U'){
// int k; cin >> k;
// UndoCommands(k);
// }
// else if (type == 'P'){
// int p; cin >> p;
// // GetLetter(p);
// cout << GetLetter(p) << "\n";
// }
// }
// return 0;
// }
# | 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... |