Segments and Subsets

시간 제한2초메모리 제한2048 MB

요약
구간들이 서로 교차하지 않고 포함하거나 접하기만 하는 집합이 주어질 때, 모든 공집합이 아닌 부분집합에 대해 접한 구간을 합치거나 1씩 늘려 [0, x] 하나로 만드는 최소 비용을 구해 합을 998244353으로 나눈 나머지를 출력한다.
난이도

어려움10점 중 8점

유형
트리, 동적 계획법, 조합론, 그리디
정답자
아직 제출이 없습니다

문제

Consider a collection of segments on a coordinate axis. The coordinates of endpoints are integers from 00 to xx. 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 \[0,x]\[0, x]. 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 11 unit. This move costs 11 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 SS, let F(S)F(S) be the minimum number of coins needed to transform it into just a single segment \[0,x]\[0, x].

You are given a collection of nn segments. Consider all its 2n−12^n - 1 non-empty sub-collections, calculate FF for each of them, and find the sum of these values modulo 998,244,353998\\,244\\,353.

입력

The first line contains an integer tt (1≤t≤1051 \le t \le 10^5), the number of test cases. The test cases follow.

Each test case starts with a line containing two integers: the number of segments nn (1≤n≤1051 \le n \le 10^5) and the coordinate xx (1≤x≤1091 \le x \le 10^9). The next nn lines describe the segments. The ii-th of these lines contains two integers ℓ_i\ell\_i and r_ir\_i: the endpoints of the ii-th segment (0≤ℓ_i<r_i≤x0 \le \ell\_i < r\_i \le x).

The sum of nn over all test cases does not exceed 10510^5.

출력

For each test case, print a line with a single integer: the required sum modulo 998,244,353998\\,244\\,353.

예제1

  1. 예제 1

    입력
    3
    2 5
    1 4
    2 3
    3 8
    1 3
    3 5
    5 8
    7 10
    1 5
    2 3
    3 4
    4 5
    5 10
    6 9
    7 8
    
    예상 출력
    10
    28
    806