← Home
write a go solution for D. Segments Coveringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a linear strip divided into m cells, numbered from 1 to m from left to right.You are given n segments. Each segment is defined by four numbers: l, r, p and q — the segment covers cells from l to r inclusively and exists with probability p/q (independently).Your task is to calculate the probability that each cell is covered by exactly one segment.InputThe first line contains two integers n and m (1<=n,m<=2*10^5).Then n lines follow. The i-th of them contains four integers l_i, r_i, p_i and q_i (1<=l_i<=r_i<=m; 1<=p_i<q_i<998244353).OutputPrint a single integer — the probability that each cell is covered by exactly one segment, taken modulo 998244353.Formally, the probability can be expressed as an irreducible fraction x/y. You have to print the value of x*y^-1bmod998244353, where y^-1 is an integer such that y*y^-1bmod998244353=1.ExamplesInput3 31 2 1 33 3 1 21 3 2 3Output610038216
Input2 31 2 1 22 3 1 2Output0
Input8 51 3 1 21 5 1 61 4 4 55 5 1 74 5 1 24 5 2 53 3 2 71 2 1 3Output94391813
NoteIn the first example, the probability is equal to 5/18.. Output only the code with no comments, explanation, or additional text.