結果

問題 No.2230 Good Omen of White Lotus
ユーザー umimelumimel
提出日時 2023-02-25 01:22:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,945 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 175,560 KB
実行使用メモリ 10,412 KB
最終ジャッジ日時 2023-10-11 07:34:40
合計ジャッジ時間 6,478 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 33 ms
5,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 47 ms
6,076 KB
testcase_17 AC 47 ms
6,084 KB
testcase_18 AC 47 ms
6,176 KB
testcase_19 AC 47 ms
6,196 KB
testcase_20 AC 4 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 5 ms
4,348 KB
testcase_23 AC 6 ms
4,348 KB
testcase_24 AC 3 ms
7,144 KB
testcase_25 AC 4 ms
7,104 KB
testcase_26 AC 3 ms
7,200 KB
testcase_27 AC 62 ms
10,200 KB
testcase_28 AC 64 ms
10,228 KB
testcase_29 AC 69 ms
10,232 KB
testcase_30 AC 75 ms
10,280 KB
testcase_31 AC 73 ms
10,408 KB
testcase_32 AC 71 ms
10,412 KB
testcase_33 AC 115 ms
10,292 KB
testcase_34 AC 120 ms
10,348 KB
testcase_35 AC 117 ms
10,288 KB
testcase_36 AC 113 ms
10,216 KB
testcase_37 AC 111 ms
10,304 KB
testcase_38 AC 111 ms
10,332 KB
testcase_39 AC 111 ms
10,292 KB
testcase_40 AC 34 ms
7,972 KB
testcase_41 AC 32 ms
5,884 KB
testcase_42 AC 64 ms
6,152 KB
testcase_43 AC 7 ms
7,280 KB
testcase_44 AC 89 ms
7,808 KB
testcase_45 AC 36 ms
6,236 KB
testcase_46 AC 58 ms
8,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

ll pow_mod(ll x, ll n, ll mod){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret*x)%mod;
        x = x*x%mod;
        n >>=1;
    }
    return ret;
}

struct SegmentTree{
    ll n;
    vector<ll> dat;

    SegmentTree(ll n_){
        n = 1;
        while(n < n_) n*=2;
        dat.resize(2*n, 0);
    }

    void update(ll k, ll a){
        k += n-1;
        dat[k] = a;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = max(dat[2*k+1], dat[2*k+2]);
        }
    }

    // the minimun element of [a, b)
    ll query(ll a, ll b){return query_sub(a, b, 0, 0, n);}

    ll query_sub(ll a, ll b, ll k, ll l, ll r){
        if(r <= a || b <= l){
            return 0;
        }else if(a <= l && r <= b){
            return dat[k];
        }else{
            ll vl = query_sub(a, b, 2*k+1, l, (l+r)/2);
            ll vr = query_sub(a, b, 2*k+2, (l+r)/2, r);
            return max(vl, vr);
        }
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll mod = MOD2;
    ll h, w, n, p; cin >> h >> w >> n >> p;
    vector<pll> P(n);
    rep(i, n){
        cin >> P[i].fi >> P[i].se;
        P[i].fi--; P[i].se--;
    }
    sort(all(P));
    SegmentTree ST(w);
    rep(i, n) ST.update(P[i].se, ST.query(0, P[i].se+1)+1);

    ll good = ST.query(0, w);
    ll bad = (h+w-3) - good;

    ll ans = 1;
    ll inv_p = pow_mod(p, mod-2, mod);
    ans = (ans * pow_mod(((p-2)*inv_p)%mod, good, mod))%mod;
    ans = (ans * pow_mod(((p-1)*inv_p)%mod, bad, mod))%mod;
    cout << (1 - ans + mod)%mod << endl;
}
0