#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
const int maxn = 2e7+100;
const int tree_siz = 1024*2048-1;
int left_[maxn];
int right_[maxn];
char val[maxn];
vi sizes;
vi roots;
int cur_node = 0;
char get_val(int akt, int p1, int p2, int poz)
{
if(p1 == p2) return val[akt];
if(poz <= (p1+p2)/2)
{
return get_val(left_[akt],p1,(p1+p2)/2,poz);
}
return get_val(right_[akt],(p1+p2)/2+1,p2,poz);
}
void add(int akt, int p1, int p2, int poz, char z, int prev)
{
if(p1 == p2)
{
val[akt] = z;
return;
}
if((p1+p2)/2 >= poz)
{
if(prev != -1) right_[akt] = right_[prev];
left_[akt] = cur_node++;
add(left_[akt],p1,(p1+p2)/2,poz,z,(prev != -1 ? left_[prev] : -1));
}
else
{
if(prev != -1) left_[akt] = left_[akt];
right_[akt] = cur_node++;
add(right_[akt],(p1+p2)/2+1,p2,poz,z,(prev != -1 ? right_[prev] : -1));
}
}
void Init()
{
rep(i,maxn)
{
left_[i] = -1;
right_[i] = -1;
}
sizes = {0};
roots = {0};
cur_node++;
}
void TypeLetter(char L)
{
int root = cur_node++;
add(root,0,tree_siz/2,sizes.back(),L,roots.back());
sizes.pb(sizes.back()+1);
roots.emplace_back(root);
}
void UndoCommands(int U)
{
roots.pb(roots[siz(roots)-1-U]);
sizes.pb(sizes[siz(sizes)-1-U]);
}
char GetLetter(int P)
{
return get_val(roots.back(),0,tree_siz/2,P);
}
# | 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... |