Interval
Time limit4sMemory limit512 MB
Given n intervals and m queries [A,B], find the expected union length of intervals over a uniformly random sub-range [L,R] within [A,B], modulo 998244353.
- Level
Hard9 of 10
- Topics
- Divide and conquer, Segment tree, Combinatorics, Intervals
- Solved
- No attempts yet
Statement
You are given intervals, the -th of which is .
The beauty of is the length covered by .
You are given queries. The -th query is , and you need to answer the following.
Choose uniformly at random from all integer pairs with . Find the expected beauty of .
The expected value can be written as a fraction with coprime non-negative integers and . Print .
Input
The first line contains two integers and ().
Each of the next lines contains and ().
Each of the next lines contains and ().
Output
Print lines. Line contains the answer for the -th query, taken modulo .
Hint
The input and output are large, so use fast I/O to avoid exceeding the time limit.