結果

問題 No.1030 だんしんぐぱーりない
ユーザー QCFiumQCFium
提出日時 2020-04-17 22:26:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 2,020 bytes
コンパイル時間 1,940 ms
コンパイル使用メモリ 176,940 KB
実行使用メモリ 17,440 KB
最終ジャッジ日時 2024-04-14 14:42:56
合計ジャッジ時間 9,571 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 172 ms
15,304 KB
testcase_06 AC 142 ms
12,504 KB
testcase_07 AC 99 ms
7,296 KB
testcase_08 AC 102 ms
8,960 KB
testcase_09 AC 140 ms
15,644 KB
testcase_10 AC 68 ms
6,944 KB
testcase_11 AC 161 ms
9,856 KB
testcase_12 AC 146 ms
13,980 KB
testcase_13 AC 130 ms
12,916 KB
testcase_14 AC 186 ms
13,032 KB
testcase_15 AC 95 ms
6,940 KB
testcase_16 AC 160 ms
11,360 KB
testcase_17 AC 142 ms
15,852 KB
testcase_18 AC 199 ms
13,448 KB
testcase_19 AC 113 ms
6,940 KB
testcase_20 AC 128 ms
9,856 KB
testcase_21 AC 116 ms
11,984 KB
testcase_22 AC 123 ms
10,092 KB
testcase_23 AC 160 ms
9,472 KB
testcase_24 AC 128 ms
6,944 KB
testcase_25 AC 145 ms
9,600 KB
testcase_26 AC 98 ms
6,940 KB
testcase_27 AC 111 ms
6,944 KB
testcase_28 AC 172 ms
11,552 KB
testcase_29 AC 107 ms
13,516 KB
testcase_30 AC 110 ms
10,296 KB
testcase_31 AC 123 ms
9,468 KB
testcase_32 AC 156 ms
12,744 KB
testcase_33 AC 153 ms
14,304 KB
testcase_34 AC 72 ms
6,940 KB
testcase_35 AC 276 ms
17,312 KB
testcase_36 AC 241 ms
17,308 KB
testcase_37 AC 255 ms
17,316 KB
testcase_38 AC 259 ms
17,440 KB
testcase_39 AC 250 ms
17,436 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
std::vector<int> score;
std::vector<std::vector<int> > childs;
std::vector<std::vector<int> > parent;
std::vector<int> depth;
void dfs(int i) {
	for (auto j : childs[i]) {
		depth[j] = depth[i] + 1;
		score[j] = std::max(score[j], score[i]);
		dfs(j);
	}
}
int lca(int a, int b) {
	if (a == -1) return b;
	if (b == -1) return a;
	if (depth[a] < depth[b]) std::swap(a, b);
	for (int k = 20; k--; ) if ((depth[a] - depth[b]) >> k & 1) a = parent[k][a];
	if (a == b) return a;
	for (int k = 20; k--; ) if (parent[k][a] != parent[k][b]) a = parent[k][a], b = parent[k][b];
	return parent[0][a];
}

struct SegTree {
	int n;
	std::vector<int> data;
	SegTree (const std::vector<int> &a) {
		for (n = 1; n < (int) a.size(); n <<= 1);
		data.resize(n << 1, -1);
		for (int i = 0; i < (int) a.size(); i++) data[i + n] = a[i];
		for (int i = n; --i; ) data[i] = lca(data[i << 1], data[i << 1 | 1]);
	}
	void assign(int i, int val) {
		for (data[i += n] = val; i >>= 1; ) data[i] = lca(data[i << 1], data[i << 1 | 1]);
	}
	int range_lca(int l, int r) {
		int res = -1;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (r & 1) res = lca(res, data[--r]);
			if (l & 1) res = lca(res, data[l++]);
		}
		return res;
	}
};

int main() {
	int n = ri(), k = ri(), q = ri();
	score.resize(n);
	for (auto &i : score) i = ri();
	
	std::vector<int> pos(k);
	for (auto &i : pos) i = ri() - 1;
	
	childs.resize(n);
	parent.resize(20, std::vector<int>(n, -1));
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		childs[b].push_back(a);
		parent[0][a] = b;
	}
	depth.resize(n);
	dfs(0);
	for (int i = 1; i < 20; i++) for (int j = 0; j < n; j++) 
		parent[i][j] = parent[i - 1][j] == -1 ? -1 : parent[i - 1][parent[i - 1][j]];
	
	SegTree tree(pos);
	for (int i = 0; i < q; i++) {
		int t = ri();
		int x = ri() - 1;
		int y = ri() - 1;
		if (t == 1) tree.assign(x, y);
		else printf("%d\n", score[tree.range_lca(x, y + 1)]);
	}
	
	return 0;
}
0