#P7111. 青春有悔

    ID: 5902 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创O2优化生成函数块状链表,块状数组,分块洛谷月赛

青春有悔

Description

It was a competition lasting nn days. Each day, Gnar must take an exam. Due to many factors, on day ii Gnar’s theoretical maximum score is aia_i, and his actual score on that day is an uniformly random integer in [0,ai][0, a_i] (for example, not enough time, losing points on easy problems, etc.). After nn days, the organizers will settle the total score and set a cutoff line. Only those whose total score is at least the cutoff line can advance.

Countless “why” filled his mind, as if every day had flaws in performance. “Flaws... if only I could rewrite past regrets...”

Late at night, Gnar began qq rounds of daydreaming. In each daydream, Gnar returns to day pp of the competition and takes the exam in a different condition, making that day’s score an uniformly random integer in [0,x][0, x], while the other n1n-1 days are still random in [0,ai][0, a_i]. However, some subtle effects cause the cutoff line to become yy. Would his chance of advancing really be higher than in reality?

For each daydream, compute the probability of advancing modulo 998244353998244353. It is easy to prove that the answer can be written as an irreducible fraction QP\frac{Q}{P}. You should output the smallest non-negative integer RR such that RPQ(mod998244353)R \cdot P \equiv Q \pmod{998244353}.

After all, it is only a daydream. Returning to day pp with a new maximum score xx will not change the real value of apa_p. The only thing that grows is regret for youth.

Input Format

The first line contains two positive integers nn and qq, representing the number of days and the number of daydreams.

The second line contains nn integers a1,a2,,ana_1,a_2, \ldots ,a_n, representing the maximum score each day in reality.

The next qq lines each contain three integers p,x,yp,x,y, representing the day returned to in this daydream, the new maximum score, and the new cutoff line.

Output Format

Output qq lines. Each line contains one integer, the probability of advancing in the corresponding daydream modulo 998244353998244353.

2 2
1 1
1 2 2
2 0 2
499122177
0
5 3
12 16 3 15 9
1 13 25
3 10 30
4 11 17
743774619
107297923
234909256

Hint

Sample Explanation #1

In the first daydream, Gnar returns to the first day. The scores over the two days are generated uniformly at random among {0,0}\{0,0\}, {0,1}\{0,1\}, {1,0}\{1,0\}, {1,1}\{1,1\}, {2,0}\{2,0\}, {2,1}\{2,1\}. Only the last three cases can advance, so the answer is 12\frac{1}{2}.

In the second daydream, Gnar returns to the second day, and his condition becomes worse. Even if he gets the maximum score for both days, he still cannot advance.


Constraints and Notes

This problem uses bundled testdata. You must pass all test points in a Subtask to receive the score for that Subtask.

  • Subtask #1 (10 points): n,q,ai,x,y100n,q,a_i,x,y \le 100.
  • Subtask #2 (10 points): n,q,ai,x,y500n,q,a_i,x,y \le 500.
  • Subtask #3 (10 points): ai,x1a_i,x \le 1.
  • Subtask #4 (20 points): ai105\sum a_i \le 10^5.
  • Subtask #5 (25 points): q=1q = 1.
  • Subtask #6 (25 points): no special constraints.

For all testdata, it is guaranteed that 1n,q1051 \le n,q \le 10^5, 1pn1 \le p \le n, 0ai,x,y1050 \le a_i,x,y \le 10^5.

Translated by ChatGPT 5