結果

問題 No.2197 Same Dish
ユーザー simansiman
提出日時 2023-03-14 14:02:46
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,464 bytes
コンパイル時間 2,274 ms
コンパイル使用メモリ 133,804 KB
実行使用メモリ 6,296 KB
最終ジャッジ日時 2023-10-18 11:39:08
合計ジャッジ時間 4,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 12 ms
4,348 KB
testcase_14 AC 77 ms
5,504 KB
testcase_15 AC 85 ms
5,500 KB
testcase_16 AC 56 ms
4,724 KB
testcase_17 AC 50 ms
4,460 KB
testcase_18 AC 87 ms
5,504 KB
testcase_19 AC 87 ms
5,504 KB
testcase_20 AC 87 ms
5,504 KB
testcase_21 AC 77 ms
6,296 KB
testcase_22 AC 74 ms
4,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0