問題一覧 > 通常問題

No.1030 Dancing Party Night

レベル : / AI推定難易度 : 1525 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 76
作問者 : Thistle / テスター : Rho
お気に入りにしたユーザー ProblemId : 4172 / 自分の提出
問題文最終更新日: 2020-04-17 23:33:46
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 244 (順位表) の他の問題:

Problem Statement

The JOI Kingdom has $N$ towns. Each town has a value called its liveliness. The liveliness of the $i$-th town is $C_i$.
These towns are connected by $N-1$ one-way roads. The $i$-th edge connects town $E_i$ and town $F_i$ in this direction.
The JOI Kingdom forms a rooted tree with vertex $1$ as the root, and all edges are directed toward the root.

Bitaro is a beaver living in the JOI Kingdom, and he loves parties. Bitaro's number is $1$.
He also has $K-1$ relatives numbered from $2$ to $K$, and all of them love parties too.
Initially, the $i$-th beaver lives in town $A_i$.

Bitaro and his relatives regularly hold parties so that the following conditions are satisfied.

  • The beavers whose numbers satisfy $L \leq x \leq R$ are invited to the party.
  • The venue must be a town reachable by all of the beavers above.
  • Among the towns satisfying the condition above, the town with the maximum liveliness is chosen.
  • After the party ends, all the beavers return home.
Also, since they are very active, they often move to other towns.

Now, Bitaro is planning to hold $P$ parties. The $i$-th party is held by inviting the beavers $L_i \leq x \leq R_i$.

In addition, Bitaro has the ability to time-leap, so he can know when the moves will happen.
$Q-P$ moves are scheduled. In the $i$-th move, beaver $X_{i}$ is scheduled to move to town $Y_{i}$.

These $Q$ events are given in chronological order as follows.
  • When $T_i=1$: a query in which beaver $X_{i}$ moves to town $Y_{i}$ is given.
  • When $T_i=2$: a party is held, inviting beavers $L_i$ through $R_i$.

Your task, for the sake of Bitaro, who is eagerly awaiting the parties, is to find the liveliness of the town where each party is held.

Input

$N\ K\ Q$
$C_{1}\ C_{2}\ \dots\ C_{N}$
$A_{1}\ A_{2}\ \dots\ A_{K}$
$E_{1}\ F_{1}$
$E_{2}\ F_{2}$
$\dots$
$E_{N-1}\ F_{N-1}$
$T_{1}\ \dots $
$\dots\ $
$T_{Q}\ \dots $

All inputs are integers.
$1 \leq\ N,K,Q \leq\ 10^{5}$
$1 \leq\ C_{i} \leq\ 10^{9}$
$1 \leq\ A_{i} \leq\ N$
Following the edges in order leads to vertex 1.
The given graph is a directed tree.
$1 \leq T_{i} \leq 2$
When $T_i=1$, the query is given in the following format.

$1\ X_i\ Y_i$     
$1 \leq\ X_{i} \leq\ K$
$1 \leq\ Y_{i} \leq\ N$
When $T_i=2$, the query is given in the following format.
$2\ L_i\ R_i$    
$1 \leq\ L_{i}\ \leq\ R_{i} \leq\ K$

Output

Output the liveliness of the town where the party is held, and print a newline at the end.

Sample

Sample 1
Input
5 2 5
1 2 3 4 5
3 4
2 1
3 2
4 2
5 1
2 1 2
1 1 4
2 1 2
1 2 5
2 1 2
Output
2
4
1

In the 1st query, beavers 1~2 are invited to the party. The towns they can all reach are towns 1,2, so output 2, the maximum liveliness among towns 1,2.
In the 2nd query, beaver 1 moves to town 4.
In the 3rd query, beavers 1~2 are invited to the party. The towns they can all reach are towns 1,2,4, so output 4, the maximum liveliness among towns 1,2,4.
In the 4th query, beaver 2 moves to town 5.
In the 5th query, beavers 1~2 are invited to the party. The only town they can all reach is town 1, so output 1, the liveliness of town 1.

Sample 2
Input
3 4 5
86 91 20
3 3 1 2
3 1
2 1
1 3 1
2 2 3
1 3 2
2 2 2
2 3 3
Output
86
86
91

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。