This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 1000000000000000000LL
#define EPS ((ld)0.00000000001)
#define pi ((ld)3.141592653589793)
#define VV(vvvv,NNNN,xxxx); REP(iiiii,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007LL;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
int S[1000000];
int s1[1000000];
int s2[1000000];
int f1[1000000][21]; //f2[i][exp] = {node after 2^exp moves, number of letters}
int f2[1000000][21]; //f2[i][exp] = {node after 2^exp moves, number of letters}
int C;
void Init()
{
C=0;
return;
}
void AddState(ll val, ll nxt)
{
s1[C]=val; s2[C]=nxt;
if(C==0) {S[C]=1;} else {S[C]=S[nxt]+min(val+1,1);}
C++;
ll exp=0; ll curval = min(s1[nxt]+1,1); if(C==1) {curval=0;} ll ind = C-1;
f1[ind][0]=nxt; f2[ind][0]=curval;
REP(exp,1,21)
{
f1[ind][exp]=f1[f1[ind][exp-1]][exp-1]; f2[ind][exp]=f2[ind][exp-1]+f2[f1[ind][exp-1]][exp-1];
}
}
void TypeLetter(char L)
{
ll val = (ll) (L-'a');
AddState(val,max(0,(int)(C-1)));
}
void UndoCommands(int U)
{
AddState(-1,C-1-U);
}
char GetLetter(int P)
{
ll needed = S[C-1]-P;
ll curind=C-1; needed-=min(1,s1[curind]+1);
//REP(i,0,s.size()) {REP(j,0,f[i].size()) {cout<<f[i][j].ff<<" "<<f[i][j].ss<<endl;} cout<<endl;}
ll ans=s1[curind];
for(ll exp=20; exp>=0; exp--)
{
if(f2[curind][exp]<needed) {needed-=f2[curind][exp]; curind = f1[curind][exp]; continue;}
if(f2[curind][exp]>needed) {continue;}
if(s1[f1[curind][exp]]>=0) {ans = s1[f1[curind][exp]]; break;}
}
if(ans>=0) {return ((char) ans+'a');}
return ans;
}
Compilation message (stderr)
scrivener.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
5 | #pragma GCC optimization ("O3")
|
scrivener.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization ("unroll-loops")
|
scrivener.cpp: In function 'void AddState(ll, ll)':
scrivener.cpp:66:5: warning: unused variable 'exp' [-Wunused-variable]
66 | ll exp=0; ll curval = min(s1[nxt]+1,1); if(C==1) {curval=0;} ll ind = C-1;
| ^~~
# | 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... |