結果
| 問題 |
No.2230 Good Omen of White Lotus
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2023-02-24 23:27:12 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 142 ms / 2,000 ms |
| コード長 | 2,293 bytes |
| コンパイル時間 | 324 ms |
| コンパイル使用メモリ | 31,744 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-09-13 06:10:23 |
| 合計ジャッジ時間 | 4,269 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
int cmp (const void *a, const void *b) {
int *a_ = (int *)a;
int *b_ = (int *)b;
if (a_[0] > b_[0]) {
return 1;
}
if (a_[0] < b_[0]) {
return -1;
}
if (a_[1] > b_[1]) {
return 1;
}
if (a_[1] < b_[1]) {
return -1;
}
return 0;
}
long long power_mod (long long a, long long b, long long mod_num) {
long long ans = 1LL;
if (b > 0LL) {
ans = power_mod(a, b/2LL, mod_num);
ans = (ans * ans) % mod_num;
if (b%2LL == 1LL) {
ans = (ans * (a % mod_num)) % mod_num;
}
}
return ans;
}
void set_segt (int *t, int idx, int val, int size) {
idx = idx+size-1;
t[idx] = val;
while (idx > 0) {
idx = (idx-1)/2;
t[idx] = t[2*idx+1];
if (t[2*idx+2] > t[idx]) {
t[idx] = t[2*idx+2];
}
}
return;
}
int max_segt_rec (int *t, int a, int b, int k, int l, int r) {
int ans = 0;
int tmp = 0;
if (r <= a || b <= l) {
return 0;
}
if (a <= l && r <= b) {
return t[k];
}
ans = max_segt_rec(t, a, b, 2*k+1, l, (l+r)/2);
tmp = max_segt_rec(t, a, b, 2*k+2, (l+r)/2, r);
if (tmp > ans) {
ans = tmp;
}
return ans;
}
int max_segt (int *t, int a, int b, int size) {
return max_segt_rec(t, a, b, 0, 0, size);
}
int main () {
int h = 0;
int w = 0;
int n = 0;
long long p = 0LL;
int xy[200000][2] = {};
int res = 0;
long long ans = 0LL;
long long mod_num = 998244353LL;
int max = 0;
int t[600000] = {};
int size = 1;
res = scanf("%d", &h);
res = scanf("%d", &w);
res = scanf("%d", &n);
res = scanf("%lld", &p);
for (int i = 0; i < n; i++) {
res = scanf("%d", xy[i]);
res = scanf("%d", xy[i]+1);
}
qsort(xy, n, sizeof(int)*2, cmp);
while (size <= w) {
size <<= 1;
}
for (int i = 0; i < n; i++) {
int tmp = max_segt(t, 0, xy[i][1]+1, size);
set_segt(t, xy[i][1], tmp+1, size);
}
max = max_segt(t, 0, w+1, size);
ans = power_mod(p-2LL, (long long)max, mod_num);
ans *= power_mod(p-1LL, (long long)(h+w-3-max), mod_num);
ans %= mod_num;
ans *= power_mod(p, ((long long)(h+w-3))*(mod_num-2LL), mod_num);
ans %= mod_num;
ans = 1LL+mod_num-ans;
ans %= mod_num;
printf("%lld\n", ans);
return 0;
}
chro_96