Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ret2home/Library

:warning: structure/PersistentArray.cpp

Depends on

Required by

Code

#pragma once
#include "../template/template.cpp"

template <class T>
struct PersistentArray {
    struct Node {
        T val;
        Node *ch[20];
    };
    void destructive_set(ll idx, T val, Node *&t) {
        if (!t) t = new Node();
        if (idx == 0)
            t->val = val;
        else
            destructive_set(idx / 20, val, t->ch[idx % 20]);
    }
    Node *set(ll idx, T val, Node *t) {
        Node *res = (t ? new Node(*t) : new Node());
        if (idx == 0)
            res->val = val;
        else
            res->ch[idx % 20] = set(idx / 20, val, res->ch[idx % 20]);
        return res;
    }
    T get(ll idx, Node *t) {
        assert(t);
        if (!idx) return t->val;
        return get(idx / 20, t->ch[idx % 20]);
    }
};
#line 2 "template/template.cpp"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define REV(i, n) for (int i = n - 1; i > 0; i--)
#define all(v) v.begin(), v.end()
#define PL pair<ll, ll>
#define PI pair<int, int>
#define pi acos(-1)
#define len(s) (int)s.size()
#define compress(v) \
    sort(all(v));   \
    v.erase(unique(all(v)), v.end());
#define comid(v, x) lower_bound(all(v), x) - v.begin()

template<class T>
using prique=priority_queue<T,vector<T>,greater<>>;

template <class T, class U>
inline bool chmin(T &a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T, class U>
inline bool chmax(T &a, U b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
constexpr ll inf = 3e18;
#line 3 "structure/PersistentArray.cpp"

template <class T>
struct PersistentArray {
    struct Node {
        T val;
        Node *ch[20];
    };
    void destructive_set(ll idx, T val, Node *&t) {
        if (!t) t = new Node();
        if (idx == 0)
            t->val = val;
        else
            destructive_set(idx / 20, val, t->ch[idx % 20]);
    }
    Node *set(ll idx, T val, Node *t) {
        Node *res = (t ? new Node(*t) : new Node());
        if (idx == 0)
            res->val = val;
        else
            res->ch[idx % 20] = set(idx / 20, val, res->ch[idx % 20]);
        return res;
    }
    T get(ll idx, Node *t) {
        assert(t);
        if (!idx) return t->val;
        return get(idx / 20, t->ch[idx % 20]);
    }
};
Back to top page