結果

問題 No.2197 Same Dish
ユーザー rabimearabimea
提出日時 2023-01-25 14:51:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,094 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 202,112 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-09 02:19:43
合計ジャッジ時間 4,492 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 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 33 ms
4,508 KB
testcase_22 AC 33 ms
5,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using pii = pair <int, int>;
const ll mod = 998244353;
//~ const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 2e5 + 11;

int b[N];
int lb(int x) { return x & (-x); }
void update(int p, int c) {
	for(int i = p; i < N; i += lb(i))
		b[i] += c;
}
int query(int p) {
	int r = 0;
	for(int i = p; i; i -= lb(i))
		r += b[i];
	return r;
}

struct seg {
	int l, r;
	bool operator <(const seg &s) const {
		return r < s.r;
	}
}s[N];

int main() {
	ios :: sync_with_stdio(false);
	
	int n, m; cin >> n >> m;
	for(int i = 0; i < n; i ++) {
		cin >> s[i].l >> s[i].r;
		s[i].r --;
	}
	sort(s, s + n);
	
	ll ans = 1;
	for(int i = 0; i < n; i ++) {
		ll t = query(N - 1) - query(s[i].l - 1);
		
		if(t > m) ans = 0;
		else ans = ans * (m - t) % mod;
		
		update(s[i].r, 1);
	}
	
	ans = (qpow(m, n) - ans + mod) % mod;
	
	cout << ans << '\n';
}
0