結果
| 問題 |
No.2197 Same Dish
|
| コンテスト | |
| ユーザー |
ぷら
|
| 提出日時 | 2023-01-29 19:59:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 1,568 bytes |
| コンパイル時間 | 1,928 ms |
| コンパイル使用メモリ | 204,176 KB |
| 最終ジャッジ日時 | 2025-02-10 07:40:27 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#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;
}
ぷら