TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Given an $N$ vertices tree. Edges are $(u_ i, v_ i)$ and a linear function $f_ i(x) = a_ i x + b_ i$ is written on the vertex $i$ for each $i$. Process $Q$ queries as follows:

  • 0 p c d: Set $f_ p \gets cx + d$
  • 1 u v x: Let vertices on the path between $u$ and $v$ be $p_ 1 = u, p_ 2, ..., p_ k = v$. Print $f_ {p_ k}(...f_ {p_ 2}(f_ {p_ 1}(x))) \bmod 998244353$

Input Format

$N$ $Q$
$a_ 0$ $b_ 0$
$a_ 1$ $b_ 1$
:
$a_ {N - 1}$ $b_ {N - 1}$
$u_ 0$ $v_ 0$
$u_ 1$ $v_ 1$
:
$u_ {N - 2}$ $v_ {N - 2}$
$\textrm{Query}_ 0$
$\textrm{Query}_ 1$
:
$\textrm{Query}_ {Q - 1}$

Output Format

Sample Input 1

5 5
1 2
3 4
5 6
7 8
9 10
0 1
1 2
2 3
2 4
1 0 3 11
1 2 4 12
0 2 13 14
1 0 4 15
1 2 2 16

Sample Output 1

1555
604
6571
222

Sample Input 2

7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 8
0 1
1 2
0 3
3 4
0 5
5 6
1 2 4 1
1 4 6 1
1 6 2 1
0 1 20 30
1 2 4 1
1 4 6 1
1 6 2 1

Sample Output 2

411
2199
607
3471
2199
6034

Hints

  • $1 \leq N, Q \leq 2 \times 10^ {5}$
  • $1 \leq a_ i, c < 998244353$
  • $0 \leq b_ i, d, x < 998244353$
  • $0 \leq p < N$
  • $0 \leq u, v < N$

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 2097152 2097152
1 5000 2097152 2097152
2 5000 2097152 2097152
3 5000 2097152 2097152
4 5000 2097152 2097152
5 5000 2097152 2097152
6 5000 2097152 2097152
7 5000 2097152 2097152
8 5000 2097152 2097152
9 5000 2097152 2097152
10 5000 2097152 2097152
11 5000 2097152 2097152
12 5000 2097152 2097152
13 5000 2097152 2097152
14 5000 2097152 2097152
15 5000 2097152 2097152
16 5000 2097152 2097152
17 5000 2097152 2097152
18 5000 2097152 2097152
19 5000 2097152 2097152