結果

問題 No.2230 Good Omen of White Lotus
ユーザー rabimearabimea
提出日時 2023-02-24 22:26:21
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,234 bytes
コンパイル時間 2,309 ms
コンパイル使用メモリ 208,920 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-13 05:42:34
合計ジャッジ時間 6,446 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

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 vl = vector <ll>;
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];
void update(int p, int v) {
	for(int i = p; i < N; i += i & (-i))
		b[i] = max(b[i], v);
}
int query(int p) {
	int r = 0;
	for(int i = p; i; i -= i & (-i))
		r = max(r, b[i]);
	return r;
}

int main() {
	ios::sync_with_stdio(0);
	int n, m, k, p; cin >> n >> m >> k >> p;
	
	vector <pii> v;
	for(int i = 0; i < k; i ++) {
		int x, y; cin >> x >> y;
		v.pb({x, y});
	}
	
	sort(v.begin(), v.end());
	
	int ma = 0;
	for(auto [x, y] : v) {
		int t = query(y);
		ma = max(ma, t + 1);
		update(y, t + 1);
	}
	
	ll x = 1;
	//~ cout << ma << '\n';
	
	for(int i = 0; i < ma; i ++) {
		x = x * (p - 2) % mod * qpow(p, mod - 2);
		x %= mod;
	}
	
	for(int i = 0; i < n + m - 3 - ma; i ++) {
		x = x * (p - 1) % mod * qpow(p, mod - 2);
		x %= mod;
	}
	
	ll ans = (1 - x) % mod;
	if(ans < 0) ans += mod;
	
	cout << ans << '\n';
}
0