結果
問題 | No.1030 だんしんぐぱーりない |
ユーザー | SSRS |
提出日時 | 2020-04-17 23:50:19 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,666 bytes |
コンパイル時間 | 1,934 ms |
コンパイル使用メモリ | 179,008 KB |
実行使用メモリ | 21,680 KB |
最終ジャッジ日時 | 2024-10-03 16:13:31 |
合計ジャッジ時間 | 13,088 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | RE | - |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | RE | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | RE | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | WA | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | WA | - |
testcase_33 | RE | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 2 ms
5,248 KB |
testcase_41 | AC | 2 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int INF = 2000000000; vector<vector<int>> child(vector<vector<int>> E, int r){ int N = E.size(); vector<vector<int>> c(N); queue<int> Q; Q.push(r); while (!Q.empty()){ int v = Q.front(); Q.pop(); for (int w : E[v]){ if (c[w].empty()){ c[v].push_back(w); Q.push(w); } } } return c; } void dfs_c(vector<int> &C, vector<vector<int>> &c, int v){ for (int w : c[v]){ C[w] = max(C[v], C[w]); dfs_c(C, c, w); } } void dfs2(vector<int> &ET, vector<int> &pos, vector<vector<int>> &c, int v){ pos[v] = ET.size(); ET.push_back(v); for (int w : c[v]){ dfs2(ET, pos, c, w); ET.push_back(v); } } vector<int> segtree_min(vector<int> &A){ int N = 1; while (N < A.size()){ N = N * 2; } vector<int> ST(N * 2 - 1); for (int i = 0; i < A.size(); i++){ ST[i + N - 1] = A[i]; } for (int i = A.size() + N - 1; i < N * 2 - 1; i++){ ST[i] = INF; } for (int i = N - 2; i >= 0; i--){ ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]); } return ST; } void segtree_min_update(vector<int> &ST, int i, int x){ int N = (ST.size() + 1) / 2; i = i + N - 1; ST[i] = x; while (i > 0){ i = (i - 1) / 2; ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]); } return; } int segtree_min_query(vector<int> &ST, int x, int y, int i, int L, int R){ if (y <= L || R <= x){ return INF; } else if (x <= L && R <= y){ return ST[i]; } else { int M = (L + R) / 2; int A = segtree_min_query(ST, x, y, i * 2 + 1, L, M); int B = segtree_min_query(ST, x, y, i * 2 + 2, M, R); return min(A, B); } } vector<int> segtree_max(vector<int> &A){ int N = 1; while (N < A.size()){ N = N * 2; } vector<int> ST(N * 2 - 1); for (int i = 0; i < A.size(); i++){ ST[i + N - 1] = A[i]; } for (int i = A.size() + N - 1; i < N * 2 - 1; i++){ ST[i] = 0; } for (int i = N - 2; i >= 0; i--){ ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } return ST; } void segtree_max_update(vector<int> &ST, int i, int x){ int N = (ST.size() + 1) / 2; i = i + N - 1; ST[i] = x; while (i > 0){ i = (i - 1) / 2; ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } return; } int segtree_max_query(vector<int> &ST, int x, int y, int i, int L, int R){ if (y <= L || R <= x){ return 0; } else if (x <= L && R <= y){ return ST[i]; } else { int M = (L + R) / 2; int A = segtree_max_query(ST, x, y, i * 2 + 1, L, M); int B = segtree_max_query(ST, x, y, i * 2 + 2, M, R); return max(A, B); } } int main(){ int N, K, Q; cin >> N >> K >> Q; vector<int> C(N); for (int i = 0; i < N; i++){ cin >> C[i]; } vector<int> A(K); for (int i = 0; i < K; i++){ cin >> A[i]; A[i]--; } vector<vector<int>> E(N); for (int i = 0; i < N - 1; i++){ int e, f; cin >> e >> f; e--; f--; E[e].push_back(f); E[f].push_back(e); } vector<vector<int>> c = child(E, 0); dfs_c(C, c, 0); vector<int> ET; vector<int> pos(N); dfs2(ET, pos, c, 0); for (int i = 0; i < N; i++){ A[i] = pos[A[i]]; } vector<int> ST1 = segtree_min(ET); int x = (ST1.size() + 1) / 2; vector<int> ST2 = segtree_min(A); vector<int> ST3 = segtree_max(A); int y = (ST2.size() + 1) / 2; for (int i = 0; i < Q; i++){ int T; cin >> T; if (T == 1){ int X, Y; cin >> X >> Y; X--; Y--; segtree_min_update(ST2, X, pos[Y]); segtree_max_update(ST3, X, pos[Y]); } if (T == 2){ int L, R; cin >> L >> R; L--; int left = segtree_min_query(ST2, L, R, 0, 0, y); int right = segtree_max_query(ST3, L, R, 0, 0, y); cout << C[segtree_min_query(ST1, left, right + 1, 0, 0, x)] << endl; } } }