#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define vll vector<ll>
#define sd second
#define ft first
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define pll pair<ll, ll>
#define mod 998244353
#define _set tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update>
#define inf (ll)1e15
#define PRESICION(x) cout.setf(ios::fixed,ios::floatfield); cout.precision(x);
#define dgb(x) cout<<#x<<" : "<<x<<"\n"
using namespace std;
using namespace __gnu_pbds;
ll dx[]={1, -1, 0, 0};
ll dy[]={0, 0, 1, -1};
inline ll sm(ll a, ll b){
return ((a%mod)+(b%mod))%mod;
}
inline ll ml(ll a, ll b){
return ((a%mod)*(b%mod))%mod;
}
inline ll rs(ll a, ll b){
return ((a%mod)-(b%mod)+mod)%mod;
}
ll bpow(ll a , ll b) {
if (b==0)return 1;
if (b%2!=0)return ((bpow(a, b-1)%mod)*(a%mod))%mod;
ll r=bpow (a ,b/ 2) ;
return ((r%mod)*(r%mod))%mod;
}
inline ll q(vector<ll>& v1, ll l, ll r){
return (l==0 ? v1[r]: v1[r]-v1[l-1]);
}
ll up[1000001][21];
vector<pair<ll, ll>> v1;
ll dist[1000001];
void Init(){
vector<pair<ll, ll>>().swap(v1);
for(int i=0; i<=1000000; i++){
for(int j=0; j<21; j++)up[i][j]=-1;
}
}
void TypeLetter(char L){
ll o=L-'a', o1=v1.size();
v1.push_back({1, o});
if(o1!=0){dist[o1]=dist[o1-1]+1;up[o1][0]=o1-1;}
else dist[o1]=1;
for(int i=1; i<21; i++){
if(up[o1][i-1]!=-1 && up[up[o1][i-1]][i-1]!=-1)up[o1][i]=up[up[o1][i-1]][i-1];
}
}
void UndoCommands(int U){
ll o1=v1.size();
v1.push_back({2, U});
if(o1-U-1>=0){up[o1][0]=o1-U-1;dist[o1]=dist[o1-U-1];}
else dist[o1]=0;
for(int i=1; i<21; i++){
if(up[o1][i-1]!=-1 && up[up[o1][i-1]][i-1]!=-1)up[o1][i]=up[up[o1][i-1]][i-1];
}
}
char GetLetter(int P){
P++;
ll o=v1.size();
o--;
for(int i=20; i>=0; i--){
if(up[o][i]!=-1 && dist[up[o][i]]>=P)o=up[o][i];
}
char r1='a'+v1[o].sd;
return r1;
}
/*
int main(){
//freopen("time.in", "r", stdin);freopen("time.out", "w", stdout);
//ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
//PRESICION(15)
//int t;cin>>t;while(t--)
Init();
while(1){
char r, r1;
ll a;
cin>>r;
if(r=='T'){cin>>r1;TypeLetter(r1);}
else if(r=='P'){cin>>a;cout<<GetLetter(a)<<endl;}
else {cin>>a;UndoCommands(a);}
}
}
*/
# | 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... |