結果
| 問題 |
No.2197 Same Dish
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2023-03-14 14:02:46 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 2,000 ms |
| コード長 | 1,464 bytes |
| コンパイル時間 | 4,773 ms |
| コンパイル使用メモリ | 143,872 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-18 08:02:28 |
| 合計ジャッジ時間 | 6,466 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll mod_pow(ll x, ll n, ll mod = MOD) {
ll res = 1;
while (n > 0) {
if (n & 1) {
res = res * x % mod;
}
x = x * x % mod;
n >>= 1;
}
return res;
}
struct Node {
int l;
int r;
Node(int l = -1, int r = -1) {
this->l = l;
this->r = r;
}
bool operator>(const Node &n) const {
return l > n.l;
}
};
struct Node2 {
int l;
int r;
Node2(int l = -1, int r = -1) {
this->l = l;
this->r = r;
}
bool operator>(const Node2 &n) const {
return r > n.r;
}
};
int main() {
ll N, K;
cin >> N >> K;
int L[N];
int R[N];
priority_queue <Node, vector<Node>, greater<Node>> pque_1;
for (int i = 0; i < N; ++i) {
cin >> L[i] >> R[i];
pque_1.push(Node(L[i], R[i]));
}
ll all = mod_pow(K, N);
ll cnt = 1;
priority_queue <Node2, vector<Node2>, greater<Node2>> pque_2;
while (not pque_1.empty()) {
Node node = pque_1.top();
pque_1.pop();
while (not pque_2.empty() && pque_2.top().r <= node.l) {
pque_2.pop();
}
ll m = pque_2.size();
cnt *= (K - m);
cnt %= MOD;
pque_2.push(Node2(node.l, node.r));
}
cout << (all - cnt + MOD) % MOD << endl;
return 0;
}
siman