QOJ.ac

QOJ

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

#8703. 天气预测

Statistics

在 A 国,小 B 掌握了一种用于精确预测天气的技术。

小 B 的预测技术依赖于一台机器,它是一个 $n$ 个节点的树,根是 $1$,每个节点有偶数个儿子。对于每个节点,有两个数据:采集数据与分析数据。

每天,小 B 会从自然界采集 $n$ 项数据,每项数据是 $0$ 或 $1$,其中第 $i$ 项数据会载入机器中第 $i$ 个节点的采集数据。

当数据收集完毕时,小 B 会开启机器进行计算分析数据的内容:每个节点分析数据将载入它所有儿子的分析数据与它自己的采集数据的众数。

当计算完毕后,最终如果树根节点的分析数据为 $1$,那么明天会下雨,不然明天不下雨。

但是不幸的是,有时候采集数据的工作并不是那么简单,对此,小 B 给出了他对这些数据的预估:第 $i$ 项数据为 $1$ 的概率是 $p_i$,并且所有数据的分布独立。对此,小 B 希望你帮他快速计算明天下雨的概率。当然,小 B 有时候会对一些数据进行更新,他会每次告诉你一项数据的概率发生了改变,你也需要给出每次改变后的答案。你只需要给出答案对 $998244353$ 取模的结果。

Input

第一行两个整数 $n, q$,表示树的点数以及修改个数。

下面一行 $n - 1$ 个正整数,其中第 $i$ 个正整数 $anc_{i+1}$ 表示节点 $i + 1$ 的父亲。

下面一行 $n$ 个整数 $w_i$,一开始的 $p_i = \frac{w_i}{998244354}$。

下面 $q$ 行,每行两个整数 $pos_i, v_i$,表示将 $p_{pos_i}$ 改为 $\frac{v_i}{998244354}$。

Output

一共 $q+1$ 行,每行一个整数表示一开始与每次修改后的答案对 $998244353$ 取模的结果。

Examples

Input 1

3 1
1 1
499122177 499122177 499122177
1 0

Output 1

499122177
748683265

Input 2

5 3
1 1 2 2
332748118 1 332748118 499122177 499122177
2 332748118
1 1
1 332748118

Output 2

776412275
850356301
942786334
850356301

Scoring

对于所有数据:$1 \leq n \leq 200000$, $1 \leq q \leq 50000$,且每个节点儿子个数为偶数。

$0 \leq w_i, v_i \leq 998244353$

子任务编号 $n \leq$ $q \leq $ 特殊性质 分值
1 $n \leq 100$ $q \leq 100$ $12$
2 $n \leq 200000$ $q \leq 50000$ A $20$
3 B $20$
4 C $23$
5 $25$

性质 A: $anc_{2i} = anc_{2i+1}$,且在 $[1, 2i - 1]$ 中均匀随机生成。

性质 B: 每个节点儿子个数不超过 $10$

性质 C: $anc_i = 1$

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.