結果

問題 No.1030 だんしんぐぱーりない
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-04-17 23:55:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 5,888 bytes
コンパイル時間 3,124 ms
コンパイル使用メモリ 217,972 KB
実行使用メモリ 28,020 KB
最終ジャッジ日時 2024-04-14 16:14:40
合計ジャッジ時間 11,778 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,816 KB
testcase_01 AC 4 ms
6,940 KB
testcase_02 AC 3 ms
7,128 KB
testcase_03 AC 4 ms
7,384 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 258 ms
25,432 KB
testcase_06 AC 177 ms
20,024 KB
testcase_07 AC 90 ms
12,152 KB
testcase_08 AC 100 ms
13,952 KB
testcase_09 AC 228 ms
25,192 KB
testcase_10 AC 58 ms
9,216 KB
testcase_11 AC 157 ms
15,616 KB
testcase_12 AC 223 ms
23,964 KB
testcase_13 AC 188 ms
21,524 KB
testcase_14 AC 204 ms
20,808 KB
testcase_15 AC 63 ms
7,552 KB
testcase_16 AC 182 ms
19,328 KB
testcase_17 AC 240 ms
26,656 KB
testcase_18 AC 225 ms
21,556 KB
testcase_19 AC 90 ms
11,992 KB
testcase_20 AC 138 ms
17,280 KB
testcase_21 AC 167 ms
20,200 KB
testcase_22 AC 139 ms
17,536 KB
testcase_23 AC 143 ms
16,124 KB
testcase_24 AC 91 ms
9,896 KB
testcase_25 AC 128 ms
15,104 KB
testcase_26 AC 65 ms
7,936 KB
testcase_27 AC 74 ms
7,756 KB
testcase_28 AC 186 ms
19,336 KB
testcase_29 AC 189 ms
23,860 KB
testcase_30 AC 147 ms
18,196 KB
testcase_31 AC 129 ms
16,384 KB
testcase_32 AC 183 ms
20,128 KB
testcase_33 AC 222 ms
23,992 KB
testcase_34 AC 60 ms
9,984 KB
testcase_35 AC 313 ms
28,004 KB
testcase_36 AC 313 ms
28,004 KB
testcase_37 AC 320 ms
27,880 KB
testcase_38 AC 308 ms
28,004 KB
testcase_39 AC 313 ms
28,020 KB
testcase_40 AC 4 ms
7,388 KB
testcase_41 AC 5 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct HLDecomposition {
    vector<set<int>> g; vector<int> vid, head, heavy, parent, depth, inv, in, out;
    HLDecomposition() {} HLDecomposition(int n) { init(n); }
    void init(int n) {
        g.resize(n); vid.resize(n, -1); head.resize(n); heavy.resize(n, -1);
        parent.resize(n); depth.resize(n); inv.resize(n); in.resize(n); out.resize(n);
    }
    void add(int u, int v) { g[u].insert(v); g[v].insert(u); }
	void build(int root) { dfs(root, -1); t = 0; dfs_hld(root); }

    int dfs(int curr, int prev) {
        parent[curr] = prev; int sub = 1, max_sub = 0;
        heavy[curr] = -1;
        for (int next : g[curr]) if (next != prev) {
            depth[next] = depth[curr] + 1;
            int sub_next = dfs(next, curr); sub += sub_next;
            if (max_sub < sub_next) max_sub = sub_next, heavy[curr] = next;
        }return sub;
    }

    int t = 0;
    void dfs_hld(int v = 0)
    {
        vid[v] = in[v] = t;
        t++;
        inv[in[v]] = v;
        if (0 <= heavy[v]) {
            head[heavy[v]] = head[v];
            dfs_hld(heavy[v]);
        }
        for (auto u : g[v]) if(depth[v] < depth[u])  if (u != heavy[v]) {
            head[u] = u;
            dfs_hld(u);
        }
        out[v] = t;
    }


    void foreach(int u, int v, function<void(int, int)> f) { // [x,y]
        if (vid[u] > vid[v]) swap(u, v); f(max(vid[head[v]], vid[u]), vid[v]);
        if (head[u] != head[v]) foreach(u, parent[head[v]], f);
    }
    int ancestor(int from, int times) {
        while (true) {
            if (depth[head[from]] > depth[from] - times) {
                times -= depth[from] - depth[head[from]] + 1; if (head[from] == 0)return -1; from = parent[head[from]];
            }
            else return inv[vid[from] - times];
        }
    }
    int lca(int u, int v) {
        if (vid[u] > vid[v]) swap(u, v); if (head[u] == head[v]) return u;
        return lca(u, parent[head[v]]);
    }
    int distance(int u, int v) { return depth[u] + depth[v] - 2 * depth[lca(u, v)]; }
    int child(int parent, int child, int times) {
        assert(depth[parent]<depth[child]);
        int d = distance(parent, child); assert(times - 1 <= d); return ancestor(child, d - times);
    }
    int go(int from, int to, int times) {
        int d = distance(from, to); assert(0 <= times and times <= d);
        int lc = lca(from, to); if (lc == to)return ancestor(from, times); if (lc == from)return child(from, to, times);
        int dd = distance(from, lc); if (dd <= times)return go(lc, to, times - dd); return ancestor(from, times);
    }
};
HLDecomposition hld;
#define def -1
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { 
        if (l < 0) return r;
        if (r < 0) return l;
        return hld.lca(l, r);
    };

    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2);
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i > 1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, K, Q;
int C[101010], A[101010];
vector<int> E[101010];
SegTree<int, 1 << 17> st;
//---------------------------------------------------------------------------------------------------
void dfs(int cu, int pa = -1) {
    fore(to, E[cu]) if (to != pa) {
        chmax(C[to], C[cu]);
        dfs(to, cu);
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K >> Q;
    rep(i, 0, N) cin >> C[i];
    rep(i, 0, K) cin >> A[i];

    hld.init(N);
    rep(i, 0, N - 1) {
        int a, b; cin >> a >> b;
        a--; b--;
        E[a].push_back(b);
        E[b].push_back(a);
        hld.add(a, b);
    }
    hld.build(0);

    dfs(0);

    rep(i, 0, K) st.update(i, A[i] - 1);

    rep(_, 0, Q) {
        int T; cin >> T;
        if (T == 1) {
            int X, Y; cin >> X >> Y;
            X--; Y--;
            st.update(X, Y);
        }
        else {
            int L, R; cin >> L >> R;
            L--;

            int ans = C[st.get(L, R)];
            printf("%d\n", ans);
        }
    }
}





0