Submission #197032

#TimeUsernameProblemLanguageResultExecution timeMemory
197032dennisstarCrayfish scrivener (IOI12_scrivener)C++11
100 / 100
640 ms186076 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) (V).begin(), (V).end()
#define unq(V) (V).erase(unique(all(V)), (V).end())
#define fastio ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vlm;
typedef vector<int> vim;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

struct node {
	char ch; int l, r;
}nd[31000010]; int nd_tp;
int root[1000010];
int sz[1000010], tp;

int new_node() { nd[nd_tp]={0,-1,-1}; return nd_tp++; }

inline void upd(int now, int i, int t, int s, int e, char val) {
	assert(now!=-1);
	if (s==e) { nd[now].ch=val; return ; }
	int md=(s+e)/2;
	if (t<=md) {
		nd[now].l=new_node();
		nd[now].r=(i!=-1?nd[i].r:-1);
		upd(nd[now].l, i!=-1?nd[i].l:-1, t, s, md, val);
	}
	else {
		nd[now].l=(i!=-1?nd[i].l:-1);
		nd[now].r=new_node();
		upd(nd[now].r, i!=-1?nd[i].r:-1, t, md+1, e, val);
	}
}
inline char get(int now, int t, int s, int e) {
	if (s==e) return nd[now].ch;
	int md=(s+e)/2;
	if (t<=md) return get(nd[now].l, t, s, md);
	else return get(nd[now].r, t, md+1, e);
} 

void Init() { root[0]=new_node(); tp=1; memset(sz, 0, sizeof(sz)); }

void TypeLetter(char L) {
	root[tp]=new_node();
	sz[tp]=sz[tp-1]+1;
	upd(root[tp], root[tp-1], sz[tp], 1, 1000000, L);
	tp++;
}

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

char GetLetter(int P) { return get(root[tp-1], P+1, 1, 1000000); }
#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...