結果

問題 No.1030 だんしんぐぱーりない
ユーザー ThistleThistle
提出日時 2020-04-02 03:31:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 460 ms / 2,000 ms
コード長 2,962 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 171,904 KB
実行使用メモリ 48,268 KB
最終ジャッジ日時 2023-09-15 23:19:46
合計ジャッジ時間 15,284 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
23,856 KB
testcase_01 AC 8 ms
23,892 KB
testcase_02 AC 8 ms
23,940 KB
testcase_03 AC 8 ms
23,876 KB
testcase_04 AC 8 ms
23,876 KB
testcase_05 AC 340 ms
45,144 KB
testcase_06 AC 274 ms
40,524 KB
testcase_07 AC 208 ms
30,892 KB
testcase_08 AC 203 ms
33,040 KB
testcase_09 AC 254 ms
45,320 KB
testcase_10 AC 149 ms
26,256 KB
testcase_11 AC 331 ms
35,720 KB
testcase_12 AC 282 ms
44,644 KB
testcase_13 AC 238 ms
40,220 KB
testcase_14 AC 355 ms
40,528 KB
testcase_15 AC 206 ms
24,496 KB
testcase_16 AC 306 ms
37,644 KB
testcase_17 AC 255 ms
47,296 KB
testcase_18 AC 382 ms
40,580 KB
testcase_19 AC 239 ms
30,608 KB
testcase_20 AC 245 ms
35,460 KB
testcase_21 AC 226 ms
40,324 KB
testcase_22 AC 245 ms
37,472 KB
testcase_23 AC 322 ms
35,244 KB
testcase_24 AC 276 ms
28,528 KB
testcase_25 AC 288 ms
33,432 KB
testcase_26 AC 211 ms
24,080 KB
testcase_27 AC 246 ms
24,172 KB
testcase_28 AC 330 ms
37,996 KB
testcase_29 AC 200 ms
42,616 KB
testcase_30 AC 218 ms
37,552 KB
testcase_31 AC 244 ms
35,192 KB
testcase_32 AC 301 ms
40,664 KB
testcase_33 AC 282 ms
44,984 KB
testcase_34 AC 150 ms
28,340 KB
testcase_35 AC 460 ms
48,268 KB
testcase_36 AC 438 ms
48,060 KB
testcase_37 AC 447 ms
48,000 KB
testcase_38 AC 456 ms
48,080 KB
testcase_39 AC 448 ms
48,076 KB
testcase_40 AC 8 ms
23,868 KB
testcase_41 AC 8 ms
23,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = int_fast64_t;
using ld = long double;
#define int ll
#define all(a) (a).begin(),(a).end()
#define fs first
#define sc second
#define H pair<int, int>
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
#define req(n,i) for(int (i) = (n) - 1 ; (i) >= 0 ; (i)--)
#define vec vector
#define pb emplace_back
constexpr int MXN = 500000 + 100;
constexpr ll inf = 3 * 1e18;
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; }
ll read() { ll u, k = scanf("%lld", &u); return u; }



class LCA {
	int n;
	int table[MXN][25];
	vec<int>(*e)[MXN];
	int dep[MXN];
public:
	void init(const int& size, vector<int>(&f)[MXN]) {
		n = size;
		e = &f;
		for (int i = 0; i <= n; i++) for (int j = 0; j < 25; j++)
			table[i][j] = -1;
	}
	void build(const int& st) {
		dfs(st, -1, 0);
		for (int j = 0; j < 24; j++)for (int i = 0; i <= n; i++) {
			if (table[i][j] > -1) table[i][j + 1] = table[table[i][j]][j];
		}
	}
	int get(int x, int y) {
		if (dep[x] > dep[y]) swap(x, y);
		for (int i = 24; i >= 0; i--) {
			if (((dep[y] - dep[x]) >> i) & 1) y = table[y][i];
		}
		if (x == y) return x;
		for (int i = 24; i >= 0; i--) {
			if (table[x][i] != table[y][i]) {
				x = table[x][i], y = table[y][i];
			}
		}
		return table[x][0];
	}
	int operator[](const int& x) const {
		return dep[x];
	}
private:
	void dfs(int v, int p, int d) {
		table[v][0] = p;
		dep[v] = d;
		for (auto& to : (*e)[v]) {
			if (to != p) dfs(to, v, d + 1);
		}
	}
};



int n, k, q;
vec<int>a, c;
int dp[200000];
LCA lca;
int rr;
vec<int>e[MXN];
int dat[400000];
void update(int x, int y) {
	x += rr - 1;
	dat[x] = y;
	while (x > 0) {
		x = (x - 1) / 2;
		dat[x] = dat[x * 2 + 1];
		if (dat[x * 2 + 2] >= 0) dat[x] = lca.get(dat[x], dat[x * 2 + 2]);
	}
}
int query(int i, int a, int b, int l, int r) {
	if (b <= l || r <= a) return -1;
	if (a <= l && r <= b) return dat[i];
	int x = query(i * 2 + 1, a, b, l, (l + r) / 2);
	int y = query(i * 2 + 2, a, b, (l + r) / 2, r);
	if (x < y) swap(x, y);
	if (x >= 0 && y >= 0) return lca.get(x, y);
	return x;
}
int query(int a, int b) {
	return query(0, a, b, 0, rr);
}


void dfs(int x, int p, int v) {
	dp[x] = v;
	for (auto g : e[x]) {
		dfs(g, x, max(v, c[g]));
	}
}


void solve() {
	cin >> n >> k >> q;
	a.clear(); c.clear();
	rep(i, n) c.pb(read());
	rep(i, k) a.pb(read() - 1);
	rep(i, n - 1) {
		int u, v; cin >> u >> v;
		u--; v--;
		e[v].pb(u);
	}
	rep(i, 400000) dat[i] = -1;
	lca.init(n, e);
	lca.build(0);
	rr = 1;
	while (rr < k) rr *= 2;
	rep(i, k) update(i, a[i]);
	dfs(0, -1, c[0]);
	while (q > 0) {
		q--;
		int t, x, y; cin >> t >> x >> y;
		if (t == 1) {
			x--; y--;
			update(x, y);
		}
		else {
			x--;
			int r = query(x, y);
			cout << dp[r] << endl;
		}
	}
}
signed main() {
	solve();
}
0