#P4074. [WC2013] 糖果公园

    ID: 3015 远端评测题 6000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2013莫队WC/CTSC/集训队最近公共祖先,LCA块状链表,块状数组,分块

[WC2013] 糖果公园

Description

Candyland has a Candy Park. Besides beautiful scenery and fun rides, there are many free candy distribution points, which attracts many candy-loving children to visit.

The structure of the Candy Park is peculiar. It consists of nn sightseeing spots, and each spot has a candy station. We number the spots from 11 to nn. There are n1n - 1 bidirectional roads connecting these spots, and the entire park is connected, meaning that starting from any spot, one can reach all other spots in the park via these roads.

There are mm types of candies in total, numbered from 11 to mm. Each candy station only distributes a specific type of candy. We use CiC_i to denote the candy type at spot ii.

Visitors do not like to retrace their steps. They always travel from a particular starting spot to a particular ending spot, visiting the spots along the way. This route is unique. When they pass each spot, they can taste one candy of the corresponding type.

People have different preferences for different types of candies. Based on visitor ratings, we obtained the tastiness index of candies: the tastiness index of the ii-th type of candy is ViV_i. In addition, if a visitor repeatedly tastes the same type of candy, they will feel a bit bored. According to quantitative statistics, the novelty index for the ii-th time tasting a certain type of candy is WiW_i. If a visitor tastes the jj-th type of candy for the ii-th time, their happiness index HH increases by the product of the corresponding tastiness index and novelty index, i.e., Vj×WiV_j \times W_i. The visitor’s final happiness index is the sum of these products.

Of course, the candy type distributed at each station may change from time to time (but always to one of the mm types), so that visitors can always feel surprised.

Staff member A received a task to compute each visitor’s happiness index based on recent park data. But A is not good at math and feels dizzy when seeing rows of numbers. As A’s best friend, you decide to help.

Input Format

The first line contains three positive integers n,m,qn, m, q, representing the number of spots, the number of candy types, and the number of operations.

The second line contains mm positive integers V1,V2,,VmV_1, V_2, \ldots, V_m.

The third line contains nn positive integers W1,W2,,WnW_1, W_2, \ldots, W_n.

From the 4th line to the (n+2)(n + 2)-th line, each line contains two positive integers Ai,BiA_i, B_i, indicating that there is a road directly connecting these two spots.

The (n+3)(n + 3)-th line contains nn positive integers C1,C2,,CnC_1, C_2, \ldots, C_n.

Then there are qq lines. Each line contains three integers Type,x,yType, x, y, representing an operation:

  • If TypeType is 00, then 1xn1 \le x \le n, 1ym1 \le y \le m, meaning that the candy type at spot xx is changed to yy.
  • If TypeType is 11, then 1x,yn1 \le x, y \le n, meaning a query for the happiness index along the path from xx to yy.

Output Format

In the order of the input, for each operation with Type=1Type = 1, output one line with a single positive integer representing the answer.

4 3 5
1 9 2
7 6 5 1
2 3
3 1
3 4
1 2 3 2
1 1 2
1 4 2
0 2 1
1 1 2
1 4 2
84
131
27
84

Hint

[Sample explanation]

We use

to denote nodes with CiC_i equal to 11, 22, 33. Before modification:

After changing C2C_2 to 11:

[Constraints]

For all testdata: 1Vi,Wi1061 \le V_i, W_i \le 10^6, 1Ai,Bin1 \le A_i, B_i \le n, 1Cim1 \le C_i \le m, and W1,W2,,WnW_1, W_2, \ldots, W_n is a non-increasing sequence, i.e., for any 1<in1 < i \le n, it holds that WiWi1W_i \le W_{i-1}.

Other constraint conditions are as shown in the table below:

QQ20180113072014.png

Translated by ChatGPT 5