#P9527. [JOIST 2022] 洒水器 / Sprinkler

[JOIST 2022] 洒水器 / Sprinkler

Background

JOISC2022 D3T2

Problem Description

JOI has many years of experience growing vegetables in his own garden, and now he plans to manage the IOI farm.

The IOI farm consists of NN plots of land. There are N1N-1 bidirectional roads connecting the plots, numbered from 11 to N1N-1. The ii-th road connects plots AiA_i and BiB_i. Any two plots are reachable from each other through the roads. Each plot has a sprinkler, and using a sprinkler can water nearby plots.

JOI plans to grow JOI Grain on the IOI farm. JOI Grain is a strange crop: when it is watered, its height changes immediately. At the same time, JOI Grain is fragile: if its height is greater than or equal to LL, then the top part of length LL breaks off immediately and falls. JOI harvests the fallen part.

Initially, JOI planted one JOI Grain of height HjH_j on plot jj. Over the next QQ days, JOI takes care of these JOI Grains. On day kk, JOI performs one of the following two operations:

  • Operation 11: JOI uses the sprinkler on plot XkX_k to water all plots whose distance to plot XkX_k is at most DkD_k, multiplying the height of the JOI Grain on those plots by WkW_k. Since JOI Grain may keep breaking, if a JOI Grain originally has height hh and is watered, its height becomes hWkmodLhW_k\bmod L.
  • Operation 22: JOI measures the height of the JOI Grain on plot XkX_k.

The distance between plots xx and yy is defined as the minimum number of roads on a path from plot xx to plot yy.

JOI wants the JOI Grain to grow as planned, so he wants to know in advance what height should be measured for each operation 22.

Input Format

The first line contains two integers N,LN,L, representing the number of plots and the breaking threshold of JOI Grain.

The next N1N-1 lines each contain two integers Ai,BiA_i,B_i, describing a road.

The next NN lines each contain one integer HiH_i, the initial height of the JOI Grain.

The next line contains one integer QQ, the number of operations.

The next QQ lines describe the operations. Line kk starts with TkT_k, the type of the operation, followed by:

  • If Tk=1T_k=1, this is operation 11, followed by three integers Xk,Dk,WkX_k,D_k,W_k, representing the sprinkler plot, the watering radius, and the growth parameter.
  • If Tk=2T_k=2, this is operation 22, followed by one integer XkX_k, the plot whose JOI Grain needs to be measured.

Output Format

For each operation 22, output one integer, the expected height of the JOI Grain.

4 7
1 2
2 3
3 4
1
1
1
1
11
1 2 1 2
1 1 0 2
2 1
2 2
2 3
2 4
1 4 10 2
2 1
2 2
2 3
2 4
4
2
2
1
1
4
4
2
6 10
5 6
1 2
1 4
2 6
3 6
9
2
3
4
9
1
10
1 5 1 7
2 4
1 4 1 9
1 5 0 7
2 1
1 1 1 3
1 6 1 4
2 5
2 4
2 3
4
1
4
8
2
8 10
1 3
3 5
4 7
6 7
4 5
7 8
2 4
5
8
6
4
6
2
9
3
11
1 2 2 0
2 1
1 6 1 0
2 4
2 6
1 5 2 0
2 8
1 7 2 0
2 6
2 7
2 4
5
0
0
3
0
0
0

Hint

Sample Explanation #1.

Initially, JOI planted JOI Grain of height 11 on all plots.

On the first day, JOI used the sprinkler on plot 22. The JOI Grains on plots 1,2,31,2,3 were affected and their heights were multiplied by 22. The heights of the four JOI Grains became 2,2,2,12,2,2,1.

On the second day, JOI used the sprinkler on plot 11. The JOI Grain on plot 11 was affected and its height was multiplied by 22. The heights of the four JOI Grains became 4,2,2,14,2,2,1.

On the seventh day, JOI used the sprinkler on plot 44. The JOI Grains on plots 1,2,3,41,2,3,4 were affected and their heights were multiplied by 22. The first JOI Grain became 88 and broke, so the heights of the four JOI Grains became 1,4,4,21,4,4,2.

This sample satisfies the constraints of subtasks 1,5,61,5,6.

Sample Explanation #2.

On the first day, JOI used the sprinkler on plot 55. The heights of the JOI Grains on plots 5,65,6 were multiplied by 77, becoming 63,763,7. Therefore, the JOI Grain on plot 55 kept breaking and its height became 33.

This sample satisfies the constraints of subtasks 1,2,3,61,2,3,6.

Sample Explanation #3.

This sample satisfies the constraints of subtasks 1,3,4,61,3,4,6.

Constraints.

For all testdata, it holds that:

  • 2N2000002\leq N\leq 200000.
  • 2L1092\leq L\leq 10^9.
  • 1Ai<BiN1\leq A_i\lt B_i\leq N (i[1,N1])(i\in[1,N-1]).
  • Any two plots are reachable through some roads.
  • 0Hj<L0\leq H_j\lt L (1jN)(1\leq j\leq N).
  • 1Q4000001\leq Q\leq 400000.
  • Each TkT_k is either 11 or 22.
  • For each kk with Tk=1T_k=1 (k[1,Q])(k\in[1, Q]), it is guaranteed that 1XkN,0Dk40,0Wk<L1\leq X_k\leq N, 0\leq D_k\leq 40, 0\leq W_k\lt L.
  • For each kk with Tk=2T_k=2 (k[1,Q])(k\in[1, Q]), it is guaranteed that 1XkN1\leq X_k\leq N.

The detailed additional constraints and scores for subtasks are as follows:

Subtask ID Additional Constraints Score
11 N,Q1000N,Q\le 1000 33
22 For all kk with Tk=1T_k=1, it is guaranteed that Dk1D_k\leq 1 99
33 For all kk with Tk=1T_k=1, it is guaranteed that Dk2D_k\leq 2 2929
44 For all kk with Tk=1T_k=1, it is guaranteed that Wk=0W_k=0 1212
55 For all kk with Tk=1T_k=1, it is guaranteed that Wk=2W_k=2 3030
66 No additional constraints 1717

Translated by ChatGPT 5