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;
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... |