結果

問題 No.2230 Good Omen of White Lotus
ユーザー lddlinanlddlinan
提出日時 2023-03-03 15:53:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 2,319 bytes
コンパイル時間 1,422 ms
コンパイル使用メモリ 90,884 KB
実行使用メモリ 7,620 KB
最終ジャッジ日時 2023-10-18 00:59:52
合計ジャッジ時間 7,554 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 47 ms
4,708 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 72 ms
5,580 KB
testcase_17 AC 71 ms
5,580 KB
testcase_18 AC 72 ms
5,580 KB
testcase_19 AC 72 ms
5,580 KB
testcase_20 AC 6 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 7 ms
4,348 KB
testcase_23 AC 8 ms
4,348 KB
testcase_24 AC 6 ms
4,348 KB
testcase_25 AC 6 ms
4,348 KB
testcase_26 AC 6 ms
4,348 KB
testcase_27 AC 57 ms
5,576 KB
testcase_28 AC 62 ms
5,576 KB
testcase_29 AC 90 ms
7,620 KB
testcase_30 AC 96 ms
7,620 KB
testcase_31 AC 95 ms
7,620 KB
testcase_32 AC 93 ms
7,620 KB
testcase_33 AC 139 ms
6,600 KB
testcase_34 AC 140 ms
6,600 KB
testcase_35 AC 140 ms
6,600 KB
testcase_36 AC 140 ms
6,600 KB
testcase_37 AC 140 ms
6,600 KB
testcase_38 AC 141 ms
6,600 KB
testcase_39 AC 140 ms
6,600 KB
testcase_40 AC 43 ms
4,460 KB
testcase_41 AC 41 ms
4,464 KB
testcase_42 AC 89 ms
5,336 KB
testcase_43 AC 8 ms
4,348 KB
testcase_44 AC 119 ms
6,316 KB
testcase_45 AC 44 ms
4,520 KB
testcase_46 AC 74 ms
5,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;



typedef struct { int x, y; } PNode;
PNode ps[200004];
bool mycmp(const PNode& a, const PNode& b) {
    if (a.x!=b.x) return a.x<b.x;
    return a.y<b.y;
}
int yy[200004];
int findi(int n, int v) {
    int i=0, d=n/2, ni;
    while(d) {
        while(1) {
            ni=i+d; if (ni>=n) break;
            if (yy[ni]==v) return ni;
            if (yy[ni]>v) break;
            i=ni;
        }
        d>>=1;
    }
    return i;
}
#define MOD 998244353
int expit(LL b, int m) {
    LL r=1;
    while(m) {
        if (m&1) { r*=b; r%=MOD; }
        b*=b; b%=MOD;
        m>>=1;
    }
    return r;
}
int mx, ix[1<<19];
int findm(int s, int e) {
    s+=mx; e+=mx;
    int r=ix[s];
    while(s<=e) {
        if (s&1) { r=max(r, ix[s]); s++; }
        if ((e&1)==0) { r=max(r, ix[e]); e--; }
        s>>=1; e>>=1;
    }
    return r;
}
void setv(int i, int v) {
    i+=mx;
    if (ix[i]>=v) return;
    ix[i]=v;
    i>>=1;
    while(i) {
        ix[i]=max(ix[i*2], ix[i*2+1]);
        i>>=1;
    }
}

int main() {
    int n, i, m, y, x, j, w, p, h;
    LL rp, ivp;
    scanf("%d %d %d %d", &h, &w, &n, &p);
    ivp = expit(p, MOD-2);
    for (i=0; i<n; i++) {
        scanf("%d %d", &ps[i].x, &ps[i].y);
        yy[i]=ps[i].y;
    } sort(yy, yy+n);
    m=0; for (i=0; i<n; i++) {
        if (i&&yy[i]==yy[i-1]) continue;
        yy[m++]=yy[i];
    }
    for (i=0; i<n; i++) ps[i].y=findi(m, ps[i].y);
    mx=1; while(mx<=m) mx<<=1;
    memset(ix, 0, sizeof(ix[0])*(mx+mx));
    sort(ps, ps+n, mycmp);
    for (i=0; i<n; ) {
        j=i;while(j<n&&ps[j].x==ps[i].x) {
            y=ps[j].y;
            x=findm(0, y)+1;
            setv(y, x);
            j++;
        }
        i=j;
    }
    x = ix[1]; 
    m = h+w-2-1;
    rp = 1;
    for (i=0; i<x; i++) {
        rp *= (p-2); rp%=MOD;
        rp *= ivp; rp%=MOD;
    }
    for (; i<m; i++) {
        rp *= (p-1); rp%=MOD; rp*=ivp; rp%=MOD;
    }
    rp = 1-rp; if (rp<0) rp+=MOD;
    printf("%lld\n", rp);
    return 0;
}
0