Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define loop(x, n) for(ll i = x; i < n; i++ )
- #define pb push_back
- #define MOD ll(1e9+7)
- #define all(x) x.begin(), x.end()
- #define f first
- #define s second
- #define DEBUG 1
- typedef long long ll;
- using namespace std;
- int next(int n, int k){
- return (n+k)%26;
- }
- ///
- struct Node{
- int prior, size = 1;
- int value;
- Node *l = 0, *r = 0;
- Node(int _key) {value = _key, prior = rand();}
- };
- ///
- typedef pair<Node*, Node*> Pair;
- int size(Node *v){return v ? v->size : 0;}
- void upd(Node *v){v->size = size(v->l) + size(v->r) + 1;}
- Node *merge(Node *l, Node *r){
- if(!l) return r;
- if(!r) return l;
- if(l->prior > r->prior){
- l->r = merge(l->r, r);
- upd(l);
- return l;
- }else{
- r->l = merge(l, r->l);
- upd(l);
- return r;
- }
- }
- Pair split(Node *p, int k){
- if(!p) return {0, 0};
- if(size(p->l) + 1 <= k){
- Pair q = split(p->r, k - size(p->l) - 1);
- p->l = q.second;
- upd(p);
- return {q.first, p};
- }else{
- Pair q = split(p->l, k);
- p->l = q.second;
- upd(p);
- return {q.first, p};
- }
- }
- //Node *root = 0;
- void insert(Node *root, int x) {
- Pair q= split(root, x);
- Node *t = new Node(x);
- // cout << q.f << " " << q.s << "\n";
- root = merge(q.first, merge(t, q.second ));
- // cout <<root->size <<"\n";
- }
- ///////
- ///////
- Node* ctrlx (Node *root, int l, int r) {
- Pair q1 = split(root, r);
- Pair q2 = split(q1.first, l);
- root = merge(q2.first, q1.second);
- return q2.second;
- }
- void ctrlv (Node *root, Node *v, int k) {
- Pair q = split(root, k);
- root = merge(q.first, merge(v, q.second));
- }
- ///////
- ///////
- vector<Node*> abc(26);
- void solve(){
- int n, m;
- cin >> n >> m;
- string a;
- cin >> a;
- ///построить дд /// nlogn
- // cout << abc[0];
- loop(0, n){
- // cout << abc[a[i]-'a'] <<" ";
- insert(abc[a[i]-'a'], i);
- cout << abc[a[i]-'a'] <<"\n";
- }
- loop(0, 1){
- // cout << abc[i]->size;
- }
- /*
- loop(0, m){
- int q;
- cin >> q;
- if(q == 1){
- //next
- int r, l, k;
- cin >> l >> r >> k;
- Node *v;
- loop(0, 26){
- v = ctrlx(abc[i], l, r);
- ctrlv(abc[(i+1)%26], v, l);
- }
- }else{
- // f(l, r)
- int l, r;
- cin >> l >> r;
- loop(0, 26){
- Pair qr = split(abc[i], r);
- Pair ql = split(qr.first, l);
- cout << ql.first;
- }
- }
- }
- */
- }
- int main() {
- #ifdef DEBUG
- freopen("text.txt", "r", stdin);
- cout <<"DEBUG" <<"\n";
- #else
- #endif
- // int t;
- // cin >> t;
- // loop(0, t) {
- // solve();
- //// cout<< solve_all("ananas");
- //
- // }
- solve();
- // int n;
- // cin >> n;
- // cout << n;
- return 0;
- }
Add Comment
Please, Sign In to add comment