Segments and Subsets
시간 제한2초메모리 제한2048 MB
구간들이 서로 교차하지 않고 포함하거나 접하기만 하는 집합이 주어질 때, 모든 공집합이 아닌 부분집합에 대해 접한 구간을 합치거나 1씩 늘려 [0, x] 하나로 만드는 최소 비용을 구해 합을 998244353으로 나눈 나머지를 출력한다.
문제
Consider a collection of segments on a coordinate axis. The coordinates of endpoints are integers from to . There is no intersecting pair of segments: for any two segments, either one of them contains another, or they have at most one common point.
Your goal is to transform your collection of segments into just a single segment . No other segments may remain. To achieve this, you can make moves. Each move has one of the following types:
- Select two segments that have a single common point: the right endpoint of the left segment coincides with the left endpoint of the right segment. Merge them into one segment: from leftmost to rightmost point. This move does not cost anything.
- Select one segment. Expand it to the left or to the right by unit. This move costs coin.
If, at some moment of time, there are two or more equal segments, only one of them remains, while the other disappear instantly.
For an initial collection of segments , let be the minimum number of coins needed to transform it into just a single segment .
You are given a collection of segments. Consider all its non-empty sub-collections, calculate for each of them, and find the sum of these values modulo .
입력
The first line contains an integer (), the number of test cases. The test cases follow.
Each test case starts with a line containing two integers: the number of segments () and the coordinate (). The next lines describe the segments. The -th of these lines contains two integers and : the endpoints of the -th segment ().
The sum of over all test cases does not exceed .
출력
For each test case, print a line with a single integer: the required sum modulo .