Submission #402983

#TimeUsernameProblemLanguageResultExecution timeMemory
402983Theo830Crayfish scrivener (IOI12_scrivener)C++17
100 / 100
598 ms170676 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll cur = 1;
ll nodes = 1;
ll depth[1000005];
char timi[1000005];
ll pos[1000005];
ll an[1000005][20];
void upd(ll x,ll p){
    an[x][0] = p;
    f(j,1,20){
       an[x][j] = an[an[x][j-1]][j-1];
    }
}
ll kth(ll a,ll k){
    ll pos = 0;
    ll ans = a;
    while(k > 0){
        if(k % 2){
            ans = an[ans][pos];
        }
        pos++;
        k /= 2;
    }
    return ans;
}
void Init(){
    pos[0] = 0;
    memset(an,0,sizeof an);
    depth[0] = -1;
    timi[0] = '$';
}
void TypeLetter(char L){
    ll p = pos[cur-1];
    depth[nodes] = depth[p] + 1;
    upd(nodes,p);
    timi[nodes] = L;
    pos[cur] = nodes;
    cur++;
    nodes++;
}
void UndoCommands(int U){
    pos[cur] = pos[cur - U - 1];
    cur++;
}
char GetLetter(int P){
    ll CUR = pos[cur-1];
    ///P = depth[ans]
    ///=> ans = kth(CUR,depth[CUR] - P)
    assert(depth[CUR] >= P);
    char ans = timi[kth(CUR,depth[CUR] - P)];
    return ans;
}
#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...