結果

問題 No.2197 Same Dish
ユーザー ぷらぷら
提出日時 2023-01-29 19:59:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,568 bytes
コンパイル時間 2,553 ms
コンパイル使用メモリ 208,712 KB
実行使用メモリ 5,724 KB
最終ジャッジ日時 2023-09-12 02:33:27
合計ジャッジ時間 4,038 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
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 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 30 ms
5,308 KB
testcase_15 AC 33 ms
5,448 KB
testcase_16 AC 23 ms
4,812 KB
testcase_17 AC 20 ms
4,812 KB
testcase_18 AC 34 ms
5,464 KB
testcase_19 AC 35 ms
5,724 KB
testcase_20 AC 34 ms
5,600 KB
testcase_21 AC 34 ms
5,604 KB
testcase_22 AC 32 ms
5,608 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({L[i],R[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].first,200200);
        res *= max(0,K-cnt);
        res %= mod;
        bit.add(tmp[i].second-1,1);
    }
    ans += mod-res;
    ans %= mod;
    cout << ans << endl;
}
0