Submission #987253

#TimeUsernameProblemLanguageResultExecution timeMemory
987253steveonalexCrayfish scrivener (IOI12_scrivener)C++17
0 / 100
460 ms206912 KiB
#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 depth; int parent[20]; Node(){ digit = depth = -1; memset(child, -1, sizeof child); memset(parent, 0, sizeof parent); } }; int n; vector<Node> a; Trie(){ a.push_back(Node()); a[0].depth = 1; } void add_child(int &x){ x = a.size(); a.push_back(Node()); } void add(int &cur, int digit){ if (a[cur].child[digit] == -1) add_child(a[cur].child[digit]); a[a[cur].child[digit]].parent[0] = cur; a[a[cur].child[digit]].depth = a[cur].depth + 1; cur = a[cur].child[digit]; a[cur].digit = digit; for(int j = 1; MASK(j) < a[cur].depth; ++j) { a[cur].parent[j] = a[a[cur].parent[j-1]].parent[j-1]; } } 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; P++; for(int j = 19; j>=0; --j) { int nxt = tri.a[cur].parent[j]; if (tri.a[nxt].depth > P){ cur = nxt; } } // cout << x << "\n"; return tri.a[cur].digit + 'a'; } // 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; // }

Compilation message (stderr)

scrivener.cpp: In member function 'void Trie::add(int&, int)':
scrivener.cpp:80:32: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   80 |         for(int j = 1; MASK(j) < a[cur].depth; ++j) {
      |                                ^
scrivener.cpp: In function 'char GetLetter(int)':
scrivener.cpp:111:9: warning: unused variable 'tmp' [-Wunused-variable]
  111 |     int tmp = cur;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...