結果

問題 No.2230 Good Omen of White Lotus
ユーザー umimel
提出日時 2023-02-25 01:22:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,945 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 178,508 KB
実行使用メモリ 10,508 KB
最終ジャッジ日時 2024-09-13 06:39:28
合計ジャッジ時間 5,201 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

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