問題一覧 > 通常問題

No.2197 Same Dish

レベル : / AI推定難易度 : 1625 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 106
作問者 : 👑 箱星 / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 6762 / 自分の提出
問題文最終更新日: 2022-11-28 16:43:45
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 374 (順位表) の他の問題:

Problem Statement

The gyudon restaurant "Yukiya" serves $K$ kinds of dishes.

$N$ customers visit this restaurant. Customer $i$ arrives at time $L_i$ and leaves at time $R_i-0.1$. Each customer orders exactly $1$ dish.

There are $K^N$ ways for the $N$ customers to order. Among these, how many are such that, at some time, $2$ customers who ordered the same dish are in the restaurant simultaneously?

Find the answer modulo $998244353$.

Constraints

  • $1\le N\le 10^5$
  • $1\le K\le 10^9$
  • $1\le L_i\lt R_i\le 2\times 10^5$
  • All inputs are integers.

Input

$N$ $K$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_N$ $R_N$

Output

Find the number of ways of ordering that satisfy the condition, and output it modulo $998244353$.

Sample

Sample 1
Input
3 2
1 4
3 5
5 8
Output
4

Customers $1$ and $2$ are both in the restaurant at time $3$. Customer $3$ is never in the restaurant at the same time as customers $1,2$. Therefore, it suffices to count the ways of ordering in which customers $1,2$ order the same dish, and there are $2\times 2=4$ such ways.

Sample 2
Input
5 1
31 32
41 42
59 60
26 27
53 54
Output
0

No $2$ customers are in the restaurant at the same time.

Sample 3
Input
5 4
1 10
2 9
3 8
4 7
5 6
Output
1024

All customers are in the restaurant at time $5$. Also, since there are $5$ customers and $4$ kinds of dishes, some $2$ customers have ordered the same dish. Therefore, all ways of ordering satisfy the condition.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。