Last Celebration

시간 제한5초메모리 제한1024 MB

요약
길이 D인 벽에 N개의 구간 칠하기 작업이 무작위 순서로 수행될 때, 같은 색이 이어진 극대 구간의 기대 개수를 998244353으로 나눈 나머지로 구한다.
난이도

어려움10점 중 8점

유형
확률, 조합론, 구간, 수학
정답자
아직 제출이 없습니다

문제

To commemorate the end of a memorable era, the city is holding a Last Celebration. As a grand finale, a group of NN artists has been commissioned to create a final, collaborative mural on a massive city wall. The wall has a length of DD and is divided into DD sections, numbered from 11 to DD. Before they begin, the entire wall is primed with a base color, represented as color 00.

Each artist ii is assigned a specific task: to paint the sections from l_il\_i to r_ir\_i with their designated color c_ic\_i. As the artists work, some sections might be painted over multiple times. The final color of any section is determined by the last artist to paint it.

The quality of the final artwork is determined by its diversity. A block is defined as a maximal contiguous segment of the wall painted in a single color. The diversity of the wall is the total number of blocks.

The NN artists will complete their tasks in a random order. Each of the N!N! possible permutations is equally likely. Your goal is to calculate the expected value of the wall's diversity after all artists are finished.

입력

The first line contains two integers, DD and NN — the length of the wall and the number of artists.

The following NN lines each contain three integers, l_il\_i, r_ir\_i, and c_ic\_i — the range and color for the ii-th artist.

출력

Output the expected value of the wall's diversity. Since the expectation can be rational, output it modulo 998,244,353998\\,244\\,353. Formally, if the expectation equals s/ts/t in lowest terms, print s×t−1(mod998,244,353)s\times t^{-1}\pmod{998\\,244\\,353}, where t−1t^{-1} is the modular inverse of tt modulo 998,244,353998\\,244\\,353.

제한

  • 1≤D≤1091 \le D \le 10^9
  • 1≤N≤2⋅1051 \le N \le 2 \cdot 10^5
  • 1≤l_i≤r_i≤D1 \le l\_i \le r\_i \le D
  • 1≤c_i≤N1 \le c\_i \le N

예제4

  1. 예제 1

    입력
    5 2
    1 4 1
    2 3 2
    
    예상 출력
    3
    
  2. 예제 2

    입력
    6 3
    2 3 1
    4 5 1
    1 6 2
    
    예상 출력
    332748120
    
  3. 예제 3

    입력
    1000000000 9
    1 2 1
    11 22 1
    111 222 1
    1111 2222 1
    11111 22222 1
    111111 222222 1
    1111111 2222222 1
    11111111 22222222 1
    111111111 222222222 1
    
    예상 출력
    18
    
  4. 예제 4

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