Submission #382382

#TimeUsernameProblemLanguageResultExecution timeMemory
382382aarr크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++14
100 / 100
612 ms90908 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 1000 * 1000 + 5, LG = 21;
char last = 0;
int ind = 0;

string s = "";
int sz[N];
int pos[N];
char c[N];
int par[N][LG];

void Init() {
	for (int i = 0; i < N; i++) {
		pos[i] = i;
	}
}

void TypeLetter(char L) {
	ind++;
	sz[ind] = sz[ind - 1] + 1;
	c[ind] = L;
	pos[ind] = ind;
	par[ind][0] = pos[ind - 1];
	for (int j = 1; j < LG; j++) {
		par[ind][j] = par[par[ind][j - 1]][j - 1];
	}
}

void UndoCommands(int U) {
	ind++;
	pos[ind] = pos[ind - U - 1];
	sz[ind] = sz[ind - U - 1];
}

char GetLetter(int P) {
	int v = pos[ind];
	int k = sz[ind] - P - 1;
//	cout << "71 " << k << endl;
	for (int j = LG - 1; j >= 0; j--) {
		if (k >= (1 << j)) {
			v = par[v][j];
			k -= 1 << j;
		}
	}
	return c[v];
}
#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...