제출 #1198289

#제출 시각아이디문제언어결과실행 시간메모리
1198289LudisseyCrayfish scrivener (IOI12_scrivener)C++20
100 / 100
484 ms123496 KiB
#include <bits/stdc++.h>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using namespace std;

const int LOG=21;
vector<vector<int>> parent;
vector<char> a;
vector<int> pos;
vector<int> dep;
int c=-1;

void Init() {
  parent.push_back({});
  for (int j = 0; j < LOG; j++) parent.back().push_back(0);
  dep.push_back(0);
  pos.push_back(0);
  a.push_back(' ');
  c=0;
}

void TypeLetter(char L) {
  a.push_back(L);
  parent.push_back({c});
  pos.push_back(sz(a)-1);
  dep.push_back(dep[c]+1);
  c=sz(a)-1;
  for (int j = 1; j < LOG; j++) parent.back().push_back(parent[parent[c][j-1]][j-1]);
}

void UndoCommands(int U) {
  pos.push_back(pos[sz(pos)-U-1]);
  c=pos.back();
}

char GetLetter(int P) {
  int u=c;
  P=dep[u]-(P+1);
  for (int j = LOG-1; j >= 0; j--)
  {
    if(P&(1<<j)) u=parent[u][j];
  }
  return a[u];
}
#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...