#P14451. [ICPC 2025 Xi'an R] Epilogue of Happiness

[ICPC 2025 Xi'an R] Epilogue of Happiness

题目描述

As the competition was nearing its end, a banquet was held. For decoration, there was a tree with nn light bulbs numbered from 11 to nn on it, where the ii-th bulb has a beauty\textit{beauty} of wiw_i. The bulbs are connected by n1n - 1 circuits. Specifically, for each ii from 22 to nn, there is a circuit connecting the ii-th bulb and the fif_i-th bulb (1fi<i1 \leq f_i < i).

There is a row of mm switches that control the bulbs' lighting. Pressing the ii-th switch toggles the state of all bulbs on the simple path from bulb 11 to bulb oio_i on the tree (i.e., bulbs that are on turn off, and those that are off turn on).

qq children will interact with the tree. The process for the ii-th child is described by three integers lil_i, rir_i, and xix_i:

  • Initially, all bulbs are off.
  • Then, the switches from the lil_i-th to the rir_i-th are pressed in sequence.
  • Finally, a photo is taken of the bulbs on the simple path from 11 to xix_i.

The total beauty\textit{total beauty} of a photo is the sum of the beauty\textit{beauty} of all bulbs that are on in the photo. Your task is to compute this value for each of the qq children.

输入格式

The first line of the input contains three integers nn, mm, and qq (1n,m,q51051 \leq n, m, q \leq 5 \cdot 10^5), where nn is the number of bulbs, mm is the number of switches, and qq is the number of children.

The second line of the input contains n1n-1 integers f2,f3,,fnf_2, f_3, \ldots, f_n (1fi<i1 \leq f_i < i), where fif_i represents a circuit between the ii-th bulb and the fif_i-th bulb.

The third line of the input contains nn integers w1,w2,,wnw_1, w_2, \ldots, w_n (0wi10000 \leq w_i \leq 1000), where wiw_i is the \textit{beauty} of the ii-th bulb.

The next mm lines of the input describe the switches. The ii-th line of these contains a single integer oio_i (1oin1 \leq o_i \leq n).

The next qq lines of the input describe the interaction process of the children. The ii-th line of these contains three integers lil_i, rir_i, and xix_i (1lirim1\le l_i\le r_i\le m, 1xin1\le x_i\le n).

输出格式

Output qq lines, each containing an integer, representing the total beauty\textit{total beauty} of each photo.

5 3 7
1 2 3 3
907 609 48 670 184
2
3
5
1 2 5
1 3 3
1 3 2
2 3 1
2 3 3
2 3 4
3 3 5
48
1516
1516
0
0
0
1748

提示

For the first child:

  • First, he pressed the first switch, causing the first and the second bulbs to turn on.
  • Then, he pressed the second switch, causing the first and the second bulbs to turn off while the third bulb turns on.
  • He took a photo of bulbs 1,2,31, 2, 3, and 55. In the photo, only the 3rd bulb was lit, resulting in a beauty of 4848.