結果

問題 No.2197 Same Dish
ユーザー ぷらぷら
提出日時 2023-01-29 18:59:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,574 bytes
コンパイル時間 2,524 ms
コンパイル使用メモリ 207,332 KB
実行使用メモリ 5,820 KB
最終ジャッジ日時 2023-09-12 01:32:01
合計ジャッジ時間 5,768 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 36 ms
5,820 KB
testcase_22 AC 33 ms
5,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

template <typename T>
struct BinaryIndexedTree {
    int N;
    vector<T>bit;
    BinaryIndexedTree(){}
    BinaryIndexedTree(int x) {
        N = x;
        bit.resize(x+1);
    }
    void add(int x,T y) {
        x++;
        while(x <= N) {
            bit[x] += y;
            x += x&-x;
        }
    }
    T sum(int x) {
        x++;
        T res = 0;
        while(x) {
            res += bit[x];
            x -= x&-x;
        }
        return res;
    }
    inline T sum(int l, int r) {//[l,r)
        return sum(r-1)-sum(l-1);
    }
    inline T operator[](int k) {
        return sum(k)-sum(k-1);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    vector<int>L(N),R(N);
    for(int i = 0; i < N; i++) {
        cin >> L[i] >> R[i];
    }
    long long ans = modpow(K,N);
    vector<pair<int,int>>tmp;
    for(int i = 0; i < N; i++) {
        tmp.push_back({R[i],L[i]});
    }
    sort(tmp.begin(),tmp.end());
    long long res = 1;
    BinaryIndexedTree<int>bit(200200);
    for(int i = 0; i < N; i++) {
        int cnt = bit.sum(tmp[i].second,tmp[i].first);
        res *= max(0,K-cnt);
        res %= mod;
        bit.add(tmp[i].first-1,1);
    }
    ans += mod-res;
    ans %= mod;
    cout << ans << endl;
}
0