Submission #641514

#TimeUsernameProblemLanguageResultExecution timeMemory
641514ymmCrayfish scrivener (IOI12_scrivener)C++17
34 / 100
715 ms262144 KiB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int lg = 20;

struct node {
	node *par_com[lg];
	node *par_let[lg];
	int len;
	char let;
} *cur;
	

void Init()
{
	cur = new node;
	Loop (i,0,lg) {
		cur->par_com[i] = cur;
		cur->par_let[i] = cur;
	}
	cur->len = 0;
	cur->let = 0;
}

void TypeLetter(char L)
{
	node *next = new node;
	next->par_com[0] = cur;
	next->par_let[0] = cur;
	Loop (i,0,lg-1) {
		next->par_com[i+1] = next->par_com[i]->par_com[i];
		next->par_let[i+1] = next->par_let[i]->par_let[i];
	}
	next->len = next->par_let[0]->len + 1;
	next->let = L;
	cur = next;
}

void UndoCommands(int U)
{
	node *sib = cur;
	Loop (i,0,lg) {
		if (U & (1<<i))
			sib = sib->par_com[i];
	}
	node *next = new node;
	next->par_com[0] = cur;
	next->par_let[0] = sib->par_let[0];
	Loop (i,0,lg-1) {
		next->par_com[i+1] = next->par_com[i]->par_com[i];
		next->par_let[i+1] = next->par_let[i]->par_let[i];
	}
	next->len = next->par_let[0]->len + 1;
	next->let = sib->let;
	cur = next;
}

char GetLetter(int P)
{
	P = cur->len - 1 - P;
	node *ans = cur;
	Loop (i,0,lg) {
		if (P & (1<<i))
			ans = ans->par_let[i];
	}
	return ans->let;
}
#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...