#x1022. CF1172C2 Nauuo and Pictures (hard version)

CF1172C2 Nauuo and Pictures (hard version)

Nauuo and Pictures (hard version)

题面翻译

Easy versionHard version 的唯一区别是数据范围。

一个随机图片网站上有 nn 张图片,每次访问这个网站时会显示一张图片。

但是每张图片显示的概率不一定相同。

每张图片有一个权值,设第 ii 张图片的权值为 wiw_i,则第 ii 张图片被显示的概率为 wij=1nwj\frac{w_i}{\sum_{j=1}^n w_j}

也就是说,一张图片被显示的概率与其权值成正比。

每张照片会被 "喜欢" 或 "不喜欢" ,用 aa 来表示。

ai=0a_i=0 ,则第 ii 张照片不被喜欢;若 ai=1a_i=1 ,则第 ii 张照片被喜欢。

每次访问网站时,若出现的照片被喜欢,则 wiw_i 加一,否则 wiw_i 减一。

接下来会访问该网站 mm 次,请求出每张图片在 mm 次访问后的预期权值 mod998244353\bmod 998244353 的结果 。

数据范围:1n2×1051\leqslant n \leqslant 2\times10^51m30001\leqslant m\leqslant 30001wi1\leqslant w_i

题目描述

The only difference between easy and hard versions is constraints.

Nauuo is a girl who loves random picture websites.

One day she made a random picture website by herself which includes n n pictures.

When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal probability. The i i -th picture has a non-negative weight wi w_i , and the probability of the i i -th picture being displayed is wij=1nwj \frac{w_i}{\sum_{j=1}^nw_j} . That is to say, the probability of a picture to be displayed is proportional to its weight.

However, Nauuo discovered that some pictures she does not like were displayed too often.

To solve this problem, she came up with a great idea: when she saw a picture she likes, she would add 1 1 to its weight; otherwise, she would subtract 1 1 from its weight.

Nauuo will visit the website m m times. She wants to know the expected weight of each picture after all the m m visits modulo 998244353 998244353 . Can you help her?

The expected weight of the i i -th picture can be denoted by qipi \frac {q_i} {p_i} where gcd(pi,qi)=1 \gcd(p_i,q_i)=1 , you need to print an integer ri r_i satisfying 0ri<998244353 0\le r_i<998244353 and ripiqi(mod998244353) r_i\cdot p_i\equiv q_i\pmod{998244353} . It can be proved that such ri r_i exists and is unique.

输入格式

The first line contains two integers n n and m m ( 1n2105 1\le n\le 2\cdot 10^5 , 1m3000 1\le m\le 3000 ) — the number of pictures and the number of visits to the website.

The second line contains n n integers a1,a2,,an a_1,a_2,\ldots,a_n ( ai a_i is either 0 0 or 1 1 ) — if ai=0 a_i=0 , Nauuo does not like the i i -th picture; otherwise Nauuo likes the i i -th picture. It is guaranteed that there is at least one picture which Nauuo likes.

The third line contains n n positive integers w1,w2,,wn w_1,w_2,\ldots,w_n ( wi1 w_i \geq 1 ) — the initial weights of the pictures. It is guaranteed that the sum of all the initial weights does not exceed 998244352m 998244352-m .

输出格式

The output contains n n integers r1,r2,,rn r_1,r_2,\ldots,r_n — the expected weights modulo 998244353 998244353 .

样例 #1

样例输入 #1

2 1
0 1
2 1

样例输出 #1

332748119
332748119

样例 #2

样例输入 #2

1 2
1
1

样例输出 #2

3

样例 #3

样例输入 #3

3 3
0 1 1
4 3 5

样例输出 #3

160955686
185138929
974061117

提示

In the first example, if the only visit shows the first picture with a probability of 23 \frac 2 3 , the final weights are (1,1) (1,1) ; if the only visit shows the second picture with a probability of 13 \frac1 3 , the final weights are (2,2) (2,2) .

So, both expected weights are 231+132=43 \frac2 3\cdot 1+\frac 1 3\cdot 2=\frac4 3 .

Because 33274811934(mod998244353) 332748119\cdot 3\equiv 4\pmod{998244353} , you need to print 332748119 332748119 instead of 43 \frac4 3 or 1.3333333333 1.3333333333 .

In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, w1 w_1 will be increased by 1 1 .

So, the expected weight is 1+2=3 1+2=3 .

Nauuo is very naughty so she didn't give you any hint of the third example.