이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int MAX = 1e6 + 5;
int moves = 1;
vi rt(MAX); // prev time if reverting
vi len(MAX); // depth of vertex
char ch[MAX]; // character at vertex
int par[MAX]; // parent
int binjump[MAX][25];
void Init() {
for (int i = 0; i < MAX; i++) {
rt[i] = i;
}
}
void addEdge(int n, int p, char L) { // edge from p to n, L at n
par[n] = p;
// do the binjump
binjump[n][0] = p;
for (int i = 1; i < 25; i++) {
binjump[n][i] = binjump[binjump[n][i - 1]][i - 1];
}
}
void TypeLetter(char L) {
len[moves] = len[moves - 1] + 1;
ch[moves] = L;
addEdge(moves, rt[moves - 1], L);
moves++;
}
void UndoCommands(int U) {
rt[moves] = rt[moves - U - 1];
len[moves] = len[moves - U - 1];
moves++;
}
char anc(int n, int m) { // char stored at m nodes above n
int curr = n;
for (int i = 0; i < 25; i++) {
if (m & (1 << i))
curr = binjump[curr][i];
}
return ch[curr];
}
char GetLetter(int P) {
int mv = len[rt[moves - 1]] - P - 1;
// cout<<"mv: "<<mv<<endl;
return anc(rt[moves - 1], mv);
}
# | 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... |