結果

問題 No.2197 Same Dish
ユーザー ineedyourlovepineedyourlovep
提出日時 2023-01-21 00:38:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 2,621 bytes
コンパイル時間 3,406 ms
コンパイル使用メモリ 208,508 KB
実行使用メモリ 5,648 KB
最終ジャッジ日時 2023-09-05 17:02:22
合計ジャッジ時間 4,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 11 ms
4,376 KB
testcase_14 AC 62 ms
5,432 KB
testcase_15 AC 69 ms
5,352 KB
testcase_16 AC 46 ms
4,824 KB
testcase_17 AC 41 ms
4,672 KB
testcase_18 AC 69 ms
5,436 KB
testcase_19 AC 70 ms
5,348 KB
testcase_20 AC 70 ms
5,364 KB
testcase_21 AC 70 ms
5,648 KB
testcase_22 AC 69 ms
5,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 1000000007;
const int mod = 998244353;

//MINT
struct mint {
  unsigned x;
  mint(): x(0) {}
  mint(ll x):x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(0) - *this;}
  mint operator~() const { return mint(1) / *this;}
  mint& operator+=(const mint& a) { if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a) { if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a) { x=(unsigned long long)x*a.x%mod; return *this;}
  mint& operator/=(const mint& a) { x=(unsigned long long)x*a.pow(mod-2).x%mod; return *this;}
  mint operator+(const mint& a) const { return mint(*this) += a;}
  mint operator-(const mint& a) const { return mint(*this) -= a;}
  mint operator*(const mint& a) const { return mint(*this) *= a;}
  mint operator/(const mint& a) const { return mint(*this) /= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint res = pow(t>>1);
    res *= res;
    return (t&1)?res*x:res;
  }
  bool operator<(const mint& a) const { return x < a.x;}
  bool operator==(const mint& a) const { return x == a.x;}
  bool operator!=(const mint& a) const { return x != a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream& i, mint& a) { unsigned long long t; i>>t; a=mint(t); return i;}
ostream& operator<<(ostream& o, const mint& a) { return o<<a.x;}

//Binary Indexed Tree (Fenwick Tree)
template<typename T>
struct BIT{
  int _n;
  vector<T> data;
  BIT(): _n(0) {};
  explicit BIT(int n): _n(n), data(n) {};
  void add(int p, T x){
    assert(0 <= p && p < _n);
    p++;
    while(p <= _n){
      data[p-1] += x;
      p += p&-p;
    }
  }
  T sum(int r){
    T s = 0;
    while(r > 0){
      s += data[r-1];
      r -= r&-r;
    }
    return s;
  }
  T sum(int l, int r){
    assert(0 <= l && l <= r && r <= _n);
    return sum(r) - sum(l);
  }
};

// POWER_MODver. N^k % MOD
ll mod_pow(ll n, ll k){
  ll res = 1;
  for(; k > 0; k >>= 1){
    if(k&1) res = (res*n)%mod;
    n = (n*n)%mod;
  }
  return res;
}


int main()
{
  ll n, k;
  cin >> n >> k;
  vector<int> l(n), r(n);
  rep(i, 0, n) cin >> l[i] >> r[i];
  mint ans = 1;
  vector<P> p(n);
  rep(i, 0, n) p[i] = {l[i], r[i]};
  sort(p.begin(), p.end());
  BIT<int> seg(200005);
  rep(i, 0, n) {
    auto [l, r] = p[i];
    ans *= max(0, (int)k-seg.sum(l+1, 200005));
    seg.add(r, 1);
  }
  cout << (mint)mod_pow(k, n) - ans << endl;
  return 0;
}
0