QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#9608. 皮鞋的多项式

الإحصائيات

皮鞋有一颗 $n$ 个节点的有根树,其中 $1$ 号节点为根节点。

皮鞋很喜欢多项式,所以他在每个节点上都写了一个多项式。

有一天钥匙看到了皮鞋的这棵树。对于一个节点 $x$,钥匙定义 $F(x)$ 为 $x$ 子树内所有节点上多项式的乘积。现在钥匙给了你 $q$ 个询问,每个询问形如 $x\ l\ r$,你需要告诉钥匙 $\left(\sum_{i=l}^r[x^i]F(x)\right)\bmod 998244353$ 的值。

由于钥匙急切地想知道答案,所以询问强制在线。

输入格式

第一行两个正整数 $n, q$ 表示树的节点数与询问个数。

接下来 $n$ 行,第 $i$ 行的第一个整数 $k_{i-1}$ 表示 $i-1$ 号节点的多项式次数。接下来 $k_{i-1}+1$ 个数 $a_{i-1,0} \sim a_{i-1,k_{i-1}}$ 以此表示这个多项式第 $0 \sim k_{i-1}$ 次项的系数。

接下来 $n-1$ 行每行两个正整数 $u, v$ 表示树上的一条边。

接下来 $q$ 行每行 $3$ 个整数 $x', l', r'$ 表示一组询问。真实的询问 $x=x' \operatorname{xor} \operatorname{lastans}, l=l' \operatorname{xor} \operatorname{lastans}, r=r' \operatorname{xor} \operatorname{lastans}$,其中 $\operatorname{lastans}$ 为上一组询问的答案,若没有上一组询问则 $\operatorname{lastans}$ 为 $0$。

输出格式

输出 $q$ 行,表示每组询问的答案。

样例 1

样例 1 输入

3 6
1 1 1 
1 1 1 
1 1 1 
1 2
2 3
1 0 3
10 9 10
0 3 0
3 3 3
1 1 1
2 2 2

样例 1 输出

8
3
2
3
1
0

样例 1 解释

解密后的输入为:

3 6
1 1 1
1 1 1
1 1 1
1 2
2 3
1 0 3
2 1 2
3 0 3
1 1 1
2 2 2
3 3 3

其中 $F(3)=1+x, F(2)=1+2x+x^2, F(1)=1+3x+3x^2+x^3$。

数据范围

对于 $100\%$ 的数据,满足 $1 \leq n \leq 10^5, 0 \leq k_i, \sum k_i \leq 10^5, 1 \leq q \leq 2 \times 10^5, 1 \leq u,v,x \leq n, 0 \leq l \leq r \leq \sum k_i, 0 \leq a_{i,j} \leq 998244352$。

子任务

子任务编号 特殊性质 分值
1 $n, \sum k_i \leq 2000$ 7
2 $\sum k_i=0$ 3
3 $x=1$ 20
4 $n,q \leq 5 \times 10^4, k_i=1$ 20
5 $n,q,\sum k_i \leq 2 \times 10^4$ 20
6 无特殊限制 30
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.