結果

問題 No.1030 だんしんぐぱーりない
ユーザー TAISA_TAISA_
提出日時 2020-04-17 22:59:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 3,913 bytes
コンパイル時間 2,613 ms
コンパイル使用メモリ 215,488 KB
実行使用メモリ 24,648 KB
最終ジャッジ日時 2023-07-27 01:55:48
合計ジャッジ時間 12,141 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 219 ms
21,464 KB
testcase_06 AC 199 ms
16,984 KB
testcase_07 AC 130 ms
8,980 KB
testcase_08 AC 138 ms
11,060 KB
testcase_09 AC 195 ms
21,712 KB
testcase_10 AC 80 ms
5,824 KB
testcase_11 AC 214 ms
12,828 KB
testcase_12 AC 166 ms
19,464 KB
testcase_13 AC 154 ms
17,744 KB
testcase_14 AC 245 ms
17,580 KB
testcase_15 AC 119 ms
4,964 KB
testcase_16 AC 174 ms
15,152 KB
testcase_17 AC 171 ms
22,232 KB
testcase_18 AC 245 ms
18,408 KB
testcase_19 AC 122 ms
8,032 KB
testcase_20 AC 139 ms
12,760 KB
testcase_21 AC 155 ms
16,464 KB
testcase_22 AC 140 ms
13,560 KB
testcase_23 AC 196 ms
12,332 KB
testcase_24 AC 160 ms
7,140 KB
testcase_25 AC 181 ms
12,208 KB
testcase_26 AC 106 ms
4,496 KB
testcase_27 AC 128 ms
4,548 KB
testcase_28 AC 206 ms
15,608 KB
testcase_29 AC 130 ms
19,160 KB
testcase_30 AC 128 ms
13,864 KB
testcase_31 AC 137 ms
12,496 KB
testcase_32 AC 207 ms
17,248 KB
testcase_33 AC 194 ms
20,128 KB
testcase_34 AC 85 ms
6,572 KB
testcase_35 AC 342 ms
24,648 KB
testcase_36 AC 307 ms
24,388 KB
testcase_37 AC 320 ms
24,376 KB
testcase_38 AC 318 ms
24,264 KB
testcase_39 AC 330 ms
24,572 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 998244353LL;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void vout(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
    }
}
vector<vector<int>> G;
struct LCA {
    int n;
    vector<vector<int>> par;
    vector<int> dep;
    void dfs(int i, int p) {
        par[0][i] = p;
        for (auto &e : G[i]) {
            if (e == p) continue;
            dep[e] = dep[i] + 1;
            dfs(e, i);
        }
    }
    void build(int n_) {
        n = n_;
        dep.resize(n);
        par.resize(30, vector<int>(n, -1));
        dfs(0, -1);
        for (int i = 1; i < 30; i++) {
            for (int j = 0; j < n; j++) {
                if (par[i - 1][j] != -1) {
                    par[i][j] = par[i - 1][par[i - 1][j]];
                }
            }
        }
    }
    int get(int u, int v) {
        if (dep[u] > dep[v]) swap(u, v);
        for (int i = 19; i >= 0; i--) {
            if (((dep[v] - dep[u]) >> i) & 1) v = par[i][v];
        }
        if (u == v) return u;
        for (int i = 19; i >= 0; i--) {
            if (par[i][u] != par[i][v]) {
                u = par[i][u];
                v = par[i][v];
            }
        }
        return par[0][u];
    }
};
//Point Update Range Get
template <class T>
struct Segtree {
    LCA g;
    T e;
    inline T f(const T &a, const T &b) {
        if (a == e) {
            return b;
        } else if (b == e) {
            return a;
        }
        return g.get(a, b);
    }
    inline void act(T &a, const T &b) { a = b; }
    int n;
    vector<T> dat;
    Segtree(int n_, T e) : e(e) {
        n = 1;
        while (n < n_) {
            n <<= 1;
        }
        dat.resize(2 * n, e);
    }
    void upd(int k, const T &x) {
        k += n;
        act(dat[k], x);
        k >>= 1;
        while (k > 0) {
            dat[k] = f(dat[k << 1], dat[k << 1 | 1]);
            k >>= 1;
        }
    }
    T get(const int &a, const int &b, int k, int l, int r) {
        if (b <= l || r <= a) {
            return e;
        }
        if (a <= l && r <= b) {
            return dat[k];
        }
        return f(get(a, b, k << 1, l, (l + r) >> 1),
                 get(a, b, k << 1 | 1, (l + r) >> 1, r));
    }
    inline T get(const int &a, const int &b) { //[a,b)
        if (a >= b) {
            return e;
        }
        return get(a, b, 1, 0, n);
    }
};
V<ll> ma, c;
void dfs(int i, int p, ll d) {
    ma[i] = max(d, c[i]);
    for (auto &e : G[i]) {
        if (e == p) continue;
        dfs(e, i, ma[i]);
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k, q;
    cin >> n >> k >> q;
    G.resize(n);
    V<ll> a(k);
    c.resize(n);
    ma.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < k; i++) {
        cin >> a[i];
        --a[i];
    }
    for (int i = 0; i + 1 < n; i++) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        G[u].eb(v);
        G[v].eb(u);
    }
    dfs(0, -1, -1);
    Segtree<int> lca(k + 10, -1);
    lca.g.build(n);
    for (int i = 0; i < k; i++) {
        lca.upd(i, a[i]);
    }
    while (q--) {
        int t, x, y;
        cin >> t >> x >> y;
        --x;
        --y;
        if (t == 1) {
            lca.upd(x, y);
        } else {
            int l = lca.get(x, y + 1);
            //cout << l << '\n';
            cout << ma[l] << '\n';
        }
    }
}
0