結果

問題 No.2197 Same Dish
ユーザー srjywrdnprkt
提出日時 2023-05-05 14:17:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,037 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 110,148 KB
最終ジャッジ日時 2025-02-12 17:10:07
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;

using ll = long long;
const ll modc = 998244353;

long long mod_exp(long long b, long long e, long long m){
    if (e > 0 && b == 0) return 0;
    long long ans = 1;
    b %= m;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * b) % m;
        e = e >> 1LL;
        b = (b*b) % m;
    }

    return ans;
}

int main(){

    ll N, K, t, x, L, R, now=0, ans=1;
    cin >> N >> K;
    vector<pair<ll, ll>> e(N*2);
    for (int i=0; i<N; i++){
        cin >> L >> R;
        e[2*i] = {L, 1}; //in
        e[2*i+1] = {R, 0}; //out
    }

    sort(e.begin(), e.end());
    for (int i=0; i<2*N; i++){
        tie(x, t) = e[i];
        if (t == 0) now--;
        else{
            ans *= (K-now);
            ans %= modc;
            now++;
        }
    }

    cout << (modc + mod_exp(K, N, modc) - ans) % modc << endl;

    return 0;
}
0