結果

問題 No.2861 Slime Party
ユーザー siganaisiganai
提出日時 2024-08-25 16:44:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 831 ms / 4,000 ms
コード長 19,546 bytes
コンパイル時間 2,929 ms
コンパイル使用メモリ 233,140 KB
実行使用メモリ 58,772 KB
最終ジャッジ日時 2024-08-25 17:32:42
合計ジャッジ時間 47,343 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 500 ms
58,416 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 16 ms
6,944 KB
testcase_04 AC 14 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 4 ms
6,940 KB
testcase_21 AC 772 ms
40,396 KB
testcase_22 AC 831 ms
40,528 KB
testcase_23 AC 703 ms
40,328 KB
testcase_24 AC 677 ms
40,384 KB
testcase_25 AC 760 ms
40,432 KB
testcase_26 AC 444 ms
40,412 KB
testcase_27 AC 452 ms
40,224 KB
testcase_28 AC 409 ms
40,396 KB
testcase_29 AC 482 ms
40,388 KB
testcase_30 AC 463 ms
40,444 KB
testcase_31 AC 608 ms
40,240 KB
testcase_32 AC 607 ms
40,348 KB
testcase_33 AC 605 ms
40,360 KB
testcase_34 AC 613 ms
40,452 KB
testcase_35 AC 634 ms
40,224 KB
testcase_36 AC 618 ms
40,192 KB
testcase_37 AC 623 ms
40,332 KB
testcase_38 AC 657 ms
40,340 KB
testcase_39 AC 684 ms
40,412 KB
testcase_40 AC 692 ms
40,400 KB
testcase_41 AC 698 ms
40,372 KB
testcase_42 AC 605 ms
40,404 KB
testcase_43 AC 612 ms
40,196 KB
testcase_44 AC 634 ms
40,364 KB
testcase_45 AC 618 ms
40,280 KB
testcase_46 AC 624 ms
40,380 KB
testcase_47 AC 632 ms
40,316 KB
testcase_48 AC 600 ms
40,464 KB
testcase_49 AC 787 ms
40,424 KB
testcase_50 AC 716 ms
40,488 KB
testcase_51 AC 557 ms
58,468 KB
testcase_52 AC 719 ms
58,584 KB
testcase_53 AC 762 ms
58,556 KB
testcase_54 AC 660 ms
58,544 KB
testcase_55 AC 740 ms
58,608 KB
testcase_56 AC 633 ms
58,548 KB
testcase_57 AC 629 ms
58,608 KB
testcase_58 AC 629 ms
58,432 KB
testcase_59 AC 694 ms
58,548 KB
testcase_60 AC 646 ms
58,548 KB
testcase_61 AC 636 ms
58,572 KB
testcase_62 AC 676 ms
58,772 KB
testcase_63 AC 631 ms
58,556 KB
testcase_64 AC 570 ms
58,684 KB
testcase_65 AC 655 ms
58,576 KB
testcase_66 AC 796 ms
58,544 KB
testcase_67 AC 336 ms
58,608 KB
testcase_68 AC 523 ms
58,500 KB
testcase_69 AC 418 ms
58,612 KB
testcase_70 AC 423 ms
58,576 KB
testcase_71 AC 369 ms
58,556 KB
testcase_72 AC 577 ms
58,544 KB
testcase_73 AC 592 ms
58,752 KB
testcase_74 AC 581 ms
58,596 KB
testcase_75 AC 288 ms
58,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include<bits/stdc++.h>
using namespace std;
// #pragma GCC target("avx,avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#ifdef LOCAL
#include <debug.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vul = vector<ull>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vs = vector<string>;
template<class T> using pq = priority_queue<T,vector<T>, greater<T>>;
#define overload4(_1, _2, _3, _4, name, ...) name
#define overload3(a,b,c,name,...) name
#define rep1(n) for (ll UNUSED_NUMBER = 0; UNUSED_NUMBER < (n); ++UNUSED_NUMBER)
#define rep2(i, n) for (ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n) - 1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n) - 1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (b) - 1;i >= (a);i--)
#define rrep4(i,a,b,c) for(ll i = (a) + ((b)-(a)-1) / (c) * (c);i >= (a);i -= c)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define all1(i) begin(i) , end(i)
#define all2(i,a) begin(i) , begin(i) + a
#define all3(i,a,b) begin(i) + a , begin(i) + b
#define all(...) overload3(__VA_ARGS__, all3, all2, all1)(__VA_ARGS__)
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){return *min_element(all(a));}
template<class T> auto max(const T& a){return *max_element(all(a));}
template<class... Ts> void in(Ts&... t);
#define INT(...) int __VA_ARGS__; in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__; in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__; in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; in(__VA_ARGS__)
#define VEC(type, name, size) vector<type> name(size); in(name)
#define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); in(name)
ll intpow(ll a, ll b){ll ans = 1; while(b){if(b & 1) ans *= a; a *= a; b /= 2;} return ans;}
ll modpow(ll a, ll b, ll p){ ll ans = 1; a %= p;if(a < 0) a += p;while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
bool is_clamp(ll val,ll low,ll high) {return low <= val && val < high;}
void Yes() {cout << "Yes\n";return;}
void No() {cout << "No\n";return;}
void YES() {cout << "YES\n";return;}
void NO() {cout << "NO\n";return;}
template <typename T>
T floor(T a, T b) {return a / b - (a % b && (a ^ b) < 0);}
template <typename T>
T ceil(T x, T y) {return floor(x + y - 1, y);}
template <typename T>
T bmod(T x, T y) {return x - y * floor(x, y);}
template <typename T>
pair<T, T> divmod(T x, T y) {T q = floor(x, y);return {q, x - q * y};}
namespace IO{
#define VOID(a) decltype(void(a))
struct setting{ setting(){cin.tie(nullptr); ios::sync_with_stdio(false);fixed(cout); cout.precision(15);}} setting;
template<int I> struct P : P<I-1>{};
template<> struct P<0>{};
template<class T> void i(T& t){ i(t, P<3>{}); }
void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; }
template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; }
template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); }
template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){in(get<idx>(t)...);}
template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ituple(t, make_index_sequence<tuple_size<T>::value>{});} 
#undef VOID
}
#define unpack(a) (void)initializer_list<int>{(a, 0)...}
template<class... Ts> void in(Ts&... t){ unpack(IO :: i(t)); }
#undef unpack
constexpr long double PI = 3.141592653589793238462643383279L;
template <class F> struct REC {
    F f;
    REC(F &&f_) : f(forward<F>(f_)) {}
    template <class... Args> auto operator()(Args &&...args) const { return f(*this, forward<Args>(args)...); }};

constexpr int mod = 998244353;
//constexpr int mod = 1000000007;

#line 2 "library/graph/graph-template.hpp"
template <typename T> 
struct Edge {
	int from, to;
	T cost;
	Edge() = default;
	Edge(int _to, T _cost) : from(-1), to(_to), cost(_cost) {}
	Edge(int _from, int _to, T _cost) : from(_from), to(_to), cost(_cost) {}
	bool operator < (const Edge &a) const { return cost < a.cost; }
	bool operator > (const Edge &a) const { return cost > a.cost; }
    Edge &operator = (const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
    friend ostream operator<<(ostream &os, Edge &edge) { return os << edge.to; }
};
 
template <typename T>
using Edges = vector<Edge<T>>;
template <typename T>
using Wgraph = vector<Edges<T>>;
using Ugraph = vector<vector<int>>;
Ugraph uinput(int N, int M = -1, bool is_directed = false, int origin = 1) {
    Ugraph g(N);
    if (M == -1) M = N - 1;
    while(M--) {
        int a,b;
        cin >> a >> b;
        a -= origin, b -= origin;
        g[a].push_back(b);
        if(!is_directed) g[b].push_back(a);
    }
    return g;
}
template <typename T>
Wgraph<T> winput(int N, int M = -1, bool is_directed = false,int origin = 1) {
    Wgraph<T> g(N);
    if (M == -1) M = N - 1;
    while(M--) {
        int a,b;
        T c;
        cin >> a >> b >> c;
        a -= origin, b -= origin;
        g[a].emplace_back(b,c);
        if(!is_directed) g[b].emplace_back(a,c);
    }
    return g;
}
#line 3 "library/tree/CartesianTree.hpp"
// return value : pair<graph, root>
template <typename T>
pair<vector<vector<int>>,int> CartesianTree(vector<T> &a,bool is_min) {
    int N = (int)a.size();
    vector<vector<int>> g(N);
    vector<int> p(N,-1), st;
    st.reserve(N);
    for (int i = 0;i < N;i++) {
        int prv = -1;
        if(is_min) while (!st.empty() && a[i] < a[st.back()]) {
            prv = st.back();
            st.pop_back();
        }
        else while (!st.empty() && a[i] > a[st.back()]) {
            prv = st.back();
            st.pop_back();
        }
        if (prv != -1) p[prv] = i;
        if (!st.empty()) p[i] = st.back();
        st.push_back(i);
    }
    int root = -1;
    for (int i = 0;i < N;i++) {
        if (p[i] != -1) g[p[i]].push_back(i);
        else root = i;
    }
    return make_pair(g, root);
}
#line 3 "library/tree/HLD.hpp"
template <typename G = vector<vector<int>>>
struct HLD {
    private:
    void dfs_sz(int cur) {
        size[cur] = 1;
        for (auto &dst:g[cur]) {
            if (dst == par[cur]) {
                if (g[cur].size() >= 2 && int(dst) == int(g[cur][0]))
                swap(g[cur][0],g[cur][1]);
                else continue;
            }
            depth[dst] = depth[cur] + 1;
            par[dst] = cur;
            dfs_sz(dst);
            size[cur] += size[dst];
            if (size[dst] > size[g[cur][0]]) {
                swap(dst,g[cur][0]);
            }
        }
    }
    void dfs_hld(int cur) {
        ord[id] = cur;
        down[cur] = id++;
        for (auto dst:g[cur]) {
        if (dst == par[cur]) continue;
            nxt[dst] = (int(dst) == int(g[cur][0]) ? nxt[cur] : int(dst));
            dfs_hld(dst);
        }
        up[cur] = id;
    }
    public:
  // [u, v)
    vector<pair<int,int>> ascend(int u,int v) const {
        vector<pair<int,int>> res;
        while (nxt[u] != nxt[v]) {
            res.emplace_back(down[u],down[nxt[u]]);
            u = par[nxt[u]];
        }
        if (u != v) res.emplace_back(down[u],down[v] + 1);
        return res;
    }
  // (u, v]
    vector<pair<int,int>> descend(int u,int v) const {
        if (u == v) return {};
        if (nxt[u] == nxt[v]) return {{down[u] + 1,down[v]}};
        auto res = descend(u,par[nxt[v]]);
        res.emplace_back(down[nxt[v]],down[v]);
        return res;
    }
    G g;
    int id;
    vector<int> size,depth,down,up,ord,nxt,par;
    HLD() = default;
    HLD(G& _g,int root = 0)
        : g(_g),
            id(0),
            size(g.size(),0),
            depth(g.size(),0),
            down(g.size(),-1),
            up(g.size(),-1),
            ord(g.size(),0),
            nxt(g.size(),root),
            par(g.size(),-1) {
        dfs_sz(root);
        dfs_hld(root);
    }
    void build(int root) {
        dfs_sz(root);
        dfs_hld(root);
    }
    pair<int,int> idx(int i) const {return make_pair(down[i], up[i]);}
    template <typename F>
    void path_query(int u,int v,bool vertex,const F& f) {
        int l = lca(u,v);
        for (auto &&[a,b] : ascend(u,l)) {
            int s = a + 1, t = b;
            s > t ? f(t,s) : f(s,t);
        }
        if (vertex) f(down[l], down[l] + 1);
        for (auto &&[a,b] : descend(l,v)) {
            int s = a,t = b + 1;
            s > t ? f(t,s) : f(s,t);
        }
    }
    template <typename F>
    void path_noncommutative_query(int u,int v,bool vertex,const F& f) {
        int l = lca(u,v);
        for(auto &&[a,b]:ascend(u,l)) f(a + 1,b);
        if(vertex) f(down[l],down[l] + 1);
        for(auto &&[a,b]:descend(l,v)) f(a,b + 1);
    }
    template <typename F>
    void subtree_query(int u,bool vertex,const F& f) {
        f(down[u] + int(!vertex), up[u]);
    }
    int lca(int a,int b) {
        while (nxt[a] != nxt[b]) {
            if (down[a] < down[b]) swap(a, b);
            a = par[nxt[a]];
        }
        return depth[a] < depth[b] ? a : b;
    }
    int dist(int a,int b) {return depth[a] + depth[b] - depth[lca(a, b)] * 2;}
    int kth_ancestor(int u,int k) {
        if(k < 0) return -1;
        while(u >= 0) {
            int h = nxt[u];
            if(down[u] - k >= down[h]) return ord[down[u] - k];
            k -= down[u] - down[h] + 1;
            u = par[h];
        }
        return -1;
    }
    int next(int s,int t) {
        assert(s != t && 0 <= s && s < g.size() && 0 <= t && t < g.size());
        if(depth[s] >= depth[t]) return par[s];
        int u = kth_ancestor(t,depth[t] - depth[s] - 1);
        return par[u] == s ? u : par[s];
    }
    // s - t 間のパス上の頂点のうち s から距離 i の頂点
    // (dist(s, t) < i のとき -1)
    int jump(int s,int t,int d) {
        int lc = lca(s,t);
        int d1 = depth[s] - depth[lc];
        if(d <= d1) return kth_ancestor(s,d);
        int d2 = d1 + depth[t] - depth[lc];
        if(d <= d2) return kth_ancestor(t,d2 - d);
        return -1;
    }
};
#line 2 "library/segtree/lazysegtree.hpp"
template <class S,
          S (*op)(S, S),
          S (*e)(),
          class F,
          S (*mapping)(F, S),
          F (*composition)(F, F),
          F (*id)()>
struct lazy_segtree {
  public:
    lazy_segtree() : lazy_segtree(0) {}
    explicit lazy_segtree(int n) : lazy_segtree(vector<S>(n, e())) {}
    explicit lazy_segtree(const vector<S>& v) : _n(int(v.size())) {
        log = 0;
        while ((1U << log) < (unsigned int)(_n)) log++;
        size = 1 << log;
        d = vector<S>(2 * size, e());
        lz = vector<F>(size, id());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }

    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return e();

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        S sml = e(), smr = e();
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }

        return op(sml, smr);
    }

    S all_prod() { return d[1]; }

    void apply(int p, F f) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = mapping(f, d[p]);
        for (int i = 1; i <= log; i++) update(p >> i);
    }
    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        {
            int l2 = l, r2 = r;
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
            l = l2;
            r = r2;
        }

        for (int i = 1; i <= log; i++) {
            if (((l >> i) << i) != l) update(l >> i);
            if (((r >> i) << i) != r) update((r - 1) >> i);
        }
    }

    template <bool (*g)(S)> int max_right(int l) {
        return max_right(l, [](S x) { return g(x); });
    }
    template <class G> int max_right(int l, G g) {
        assert(0 <= l && l <= _n);
        assert(g(e()));
        if (l == _n) return _n;
        l += size;
        for (int i = log; i >= 1; i--) push(l >> i);
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!g(op(sm, d[l]))) {
                while (l < size) {
                    push(l);
                    l = (2 * l);
                    if (g(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*g)(S)> int min_left(int r) {
        return min_left(r, [](S x) { return g(x); });
    }
    template <class G> int min_left(int r, G g) {
        assert(0 <= r && r <= _n);
        assert(g(e()));
        if (r == 0) return 0;
        r += size;
        for (int i = log; i >= 1; i--) push((r - 1) >> i);
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!g(op(d[r], sm))) {
                while (r < size) {
                    push(r);
                    r = (2 * r + 1);
                    if (g(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    vector<S> d;
    vector<F> lz;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
    void all_apply(int k, F f) {
        d[k] = mapping(f, d[k]);
        if (k < size) lz[k] = composition(f, lz[k]);
    }
    void push(int k) {
        all_apply(2 * k, lz[k]);
        all_apply(2 * k + 1, lz[k]);
        lz[k] = id();
    }
};
#line 103 "main.cpp"
const ll LINF = 0x1fffffffffffffff;
ll op(ll x,ll y) {return max(x,y);}
ll e() {return -LINF;}
ll mapping(ll f,ll x) { return f + x;}
ll composition (ll L,ll R) {return R + L;}
ll id() {return 0;}
#line 2 "library/data-structure/FenwickTree.hpp"
template <typename T>
struct FenwickTree{
    int N;
    T total = 0;
    vector<T> data;
    FenwickTree() = default;
    FenwickTree(int size) {init(size);}
    FenwickTree(vector<T> &v) {
        N = v.size() + 2;
        data.reserve(N + 1);
        data.emplace_back(0);
        for(auto &e:v) {
            total += e;
            data.emplace_back(e);
        }
        data.emplace_back(0);
        data.emplace_back(0);
        for (int i = 1; i < N - 1; ++i) {
            int j = i + (i & -i);
            if (j < N - 1) data[j] = data[i] + data[j];
        }
    }
    void init(int size) {
        N = size + 2;
        data.assign(N + 1,{});
    }
    // get sum of [0,k]
    T prod(int k) const {
        if (k < 0) return T{};
        T ret{};
        for (++k;k > 0;k -= k & -k) ret += data[k];
        return ret;
    }
    // get sum of [l,r)
    inline T prod(int l,int r) const {return prod(r - 1) - prod(l - 1);}
    // get value of k
    inline T get(int k) const {return prod(k) - prod(k - 1); }
    T all_prod() const {return total;}
    void add(int k, T x) { 
        total += x;
        for(++k;k < N;k += k & -k) data[k] += x;
    }
    // minimize i s.t. sum(i) >= w
    int lower_bound(T w) {
        if (w <= 0) return 0;
        int x = 0;
        for(int k = 1 <<__lg(N);k;k >>= 1) {
            if (x + k <= N - 1 && data[x + k] < w) {
                w -= data[x + k];
                x += k;
            }
        }
        return x;
    }
    // minimize i s.t. sum(i) > w
    int upper_bound(T w) {
        if (w < 0) return 0;
        int x = 0;
        for(int k = 1 <<__lg(N);k;k >>= 1) {
            if (x + k <= N - 1 && data[x + k] <= w) {
                w -= data[x + k];
                x += k;
            }
        }
        return x;
    }
};
#line 110 "main.cpp"
int main() {
    INT(n,q);
    LL(l);
    VEC(ll,a,n);
    VEC(int,x,n);
    auto [g,root] = CartesianTree<ll>(a,false);
    HLD<vvi> hld(g,root);
    vi par(n,-1);
    vl su(n);
    auto dfs = REC([&](auto &&f,int now) -> void {
        for(auto &nex:g[now]) {
            f(nex);
            su[now] += su[nex];
            par[nex] = now;
        }
        su[now] += x[now];
    });
    dfs(root);
    vl init(n,-4e18);
    rep(i,n) {
        if(i != root) {
            init[hld.idx(i).first] = a[par[i]] - su[i];
        }
    }
    FenwickTree<ll> fw(n);
    rep(i,n) {
        fw.add(hld.idx(i).first,x[i]);
    }
    lazy_segtree<ll,op,e,ll,mapping,composition,id> seg(init);
    ll update_val = 0;
    auto f1 = [&](int u,int v) {
        seg.apply(u,v,update_val);
    };
    ll ma = 0;
    auto f2 = [&](int u,int v) {
        chmax(ma,seg.prod(u,v));
    };
    ll pl = 0;
    auto f3 = [&](int u,int v) {
        pl += fw.prod(u,v);
    };
    rep(i,q) {
        INT(cmd);
        if(cmd == 1) {
            INT(a,b);
            a--;
            update_val = x[a] - b;
            hld.path_query(root,a,false,f1);
            x[a] = b;
            fw.add(hld.idx(a).first,-update_val);
        }
        else {
            INT(c);
            c--;
            if(a[c] > a[c+1]) c++;
            if(a[c] >= l) {
                cout << l << '\n';
                continue;
            }
            int now = c;
            rrep(j,18) {
                int nex = hld.kth_ancestor(now,1 << j);
                if(nex == -1) continue;
                ma = 0;
                hld.path_query(now,nex,false,f2);
                //debug(ma,nex);
                if(ma < l) now = nex;
            }
            pl = 0;
            hld.subtree_query(now,true,f3);
            cout << l + pl << '\n';
        }
    }
}
0