結果

問題 No.2197 Same Dish
ユーザー FplusFplusFFplusFplusF
提出日時 2023-01-20 22:19:32
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 2,685 ms
コンパイル使用メモリ 211,216 KB
実行使用メモリ 5,996 KB
最終ジャッジ日時 2024-06-23 10:16:41
合計ジャッジ時間 3,984 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
ll modpow(ll a,ll b,ll mod){
    if(b==0) return 1;
    ll p=a,ret=1;
    for(ll i=0;i<=62;i++){
        if(b&(1ll<<i)){
            ret*=p;
            ret%=mod;
        }
        p=(p%mod)*(p%mod);
        p%=mod;
    }
    return ret;
}
int main(){
    const ll mod=998244353;
    ll n,k;
    cin >> n >> k;
    vector<pll> p(n);
    rep(i,n) cin >> p[i].first >> p[i].second;
    sort(all(p));
    ll r=1,x=k;
    priority_queue<ll,vector<ll>,greater<ll>> pq;
    for(auto &[a,b]:p){
        while(!pq.empty()&&pq.top()<=a){
            pq.pop();
            x++;
        }
        r*=x;
        r%=mod;
        x=max(0ll,x-1);
        pq.push(b);
    }
    cout << (modpow(k,n,mod)-r+mod)%mod << endl;
}
0