Submission #589970

#TimeUsernameProblemLanguageResultExecution timeMemory
589970dariaCrayfish scrivener (IOI12_scrivener)C++14
100 / 100
467 ms134216 KiB
    #include "bits/stdc++.h"
    using namespace std;
    #define ll long long
    #define N (ll)1e6
     
    ll n = 0, t = 0;
    ll dpt[N], par[N][21], pos[N];
    char c[N];
   
    ll anc(ll a, ll p){
     for(ll i=0; i<21; ++i)
      if(p & (1 <<i))
       a = par[a][i];
     return a;
    }

    void Init(){
     
    }
     
    void TypeLetter(char L) {
     ll curr = pos[t];
     n++;
     t++;
     pos[t] = n;

     c[n] = L;
     dpt[n] = dpt[curr] + 1;
     
     par[n][0] = curr;
     for(ll i=1; i<21; ++i)
      par[n][i] = par[par[n][i-1]][i-1];    
    }
     
    void UndoCommands(int U) {
     t++;
     pos[t] = pos[t-U-1];

    }
     
    char GetLetter(int P){
     ll curr = pos[t];
     return c[anc(curr, dpt[curr]-P-1)];
    }
#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...