Submission #121250

#TimeUsernameProblemLanguageResultExecution timeMemory
121250baluteshihCrayfish scrivener (IOI12_scrivener)C++14
60 / 100
1081 ms119288 KiB
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

vector<vector<pair<int,char>>> v(1000005,vector<pair<int,char>>());
int Len[1000005],pa[20][1000005],ti[1000005],lg=19,t;

void Init(){
	t=0,Len[0]=-1;
}

int finds(int x)
{
	if(ti[x]==x) return x;
	return ti[x]=finds(ti[x]);
}

void TypeLetter(char L) 
{
	++t,ti[t]=t,Len[t]=Len[finds(t-1)]+1,v[Len[t]].pb(MP(t,L));
	pa[0][t]=finds(t-1);
	for(int i=1;i<=lg;++i)
		pa[i][t]=pa[i-1][pa[i-1][t]];
}

void UndoCommands(int U)
{
	++t,ti[t]=finds(t-U-1),Len[t]=Len[finds(t-U-1)];
}

char GetLetter(int P)
{
	int x=finds(t);
	for(int i=__lg(t);i>=0;--i)
		if(Len[pa[i][x]]>=P)
			x=pa[i][x];
	if(Len[pa[0][x]]>=P) 
		x=pa[0][x];
	auto p=lower_bound(ALL(v[P]),MP(x,'a'));
	return p->S;
}
#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...