Logo
(追記) (追記ここまで)

34659번 - Last Celebration 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 1024 MB54362969.048%

문제

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

Each artist $i$ is assigned a specific task: to paint the sections from $l_i$ to $r_i$ with their designated color $c_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 $N$ artists will complete their tasks in a random order. Each of the $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, $D$ and $N$ — the length of the wall and the number of artists.

The following $N$ lines each contain three integers, $l_i,ドル $r_i,ドル and $c_i$ — the range and color for the $i$-th artist.

출력

Output the expected value of the wall's diversity. Since the expectation can be rational, output it modulo 998ドル,244円,353円$. Formally, if the expectation equals $s/t$ in lowest terms, print $s\times t^{-1}\pmod{998,244円,353円},ドル where $t^{-1}$ is the modular inverse of $t$ modulo 998ドル,244円,353円$.

제한

  • 1ドル \le D \le 10^9$
  • 1ドル \le N \le 2 \cdot 10^5$
  • 1ドル \le l_i \le r_i \le D$
  • 1ドル \le c_i \le N$

예제 입력 1

5 2
1 4 1
2 3 2

예제 출력 1

3

예제 입력 2

6 3
2 3 1
4 5 1
1 6 2

예제 출력 2

332748120

예제 입력 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

예제 출력 3

18

예제 입력 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

예제 출력 4

356515843

노트

출처

University > KAIST > KAIST ICPC Mock Competition > 2025 KAIST 15th ICPC Mock Competition L번

University > MIT > The MIT Programming Contest > 2025-26 > MIT Team Contest 2 L번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /