結果

問題 No.2230 Good Omen of White Lotus
ユーザー tamatotamato
提出日時 2023-02-24 22:25:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 981 ms / 2,000 ms
コード長 3,010 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 165,420 KB
最終ジャッジ日時 2023-10-11 06:28:18
合計ジャッジ時間 18,091 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,932 KB
testcase_01 AC 75 ms
71,164 KB
testcase_02 AC 73 ms
71,156 KB
testcase_03 AC 74 ms
70,932 KB
testcase_04 AC 74 ms
71,260 KB
testcase_05 AC 74 ms
71,380 KB
testcase_06 AC 73 ms
71,404 KB
testcase_07 AC 74 ms
71,324 KB
testcase_08 AC 74 ms
71,264 KB
testcase_09 AC 74 ms
71,340 KB
testcase_10 AC 74 ms
71,220 KB
testcase_11 AC 73 ms
71,176 KB
testcase_12 AC 75 ms
71,308 KB
testcase_13 AC 74 ms
71,164 KB
testcase_14 AC 284 ms
86,396 KB
testcase_15 AC 88 ms
76,004 KB
testcase_16 AC 341 ms
97,700 KB
testcase_17 AC 343 ms
97,516 KB
testcase_18 AC 341 ms
97,576 KB
testcase_19 AC 340 ms
97,516 KB
testcase_20 AC 127 ms
78,188 KB
testcase_21 AC 108 ms
78,204 KB
testcase_22 AC 132 ms
78,548 KB
testcase_23 AC 134 ms
78,996 KB
testcase_24 AC 74 ms
71,132 KB
testcase_25 AC 75 ms
71,396 KB
testcase_26 AC 73 ms
71,332 KB
testcase_27 AC 375 ms
165,420 KB
testcase_28 AC 372 ms
161,496 KB
testcase_29 AC 211 ms
94,824 KB
testcase_30 AC 214 ms
90,836 KB
testcase_31 AC 372 ms
162,020 KB
testcase_32 AC 372 ms
161,604 KB
testcase_33 AC 967 ms
132,432 KB
testcase_34 AC 981 ms
132,660 KB
testcase_35 AC 976 ms
132,060 KB
testcase_36 AC 958 ms
132,580 KB
testcase_37 AC 953 ms
132,312 KB
testcase_38 AC 965 ms
132,104 KB
testcase_39 AC 959 ms
132,244 KB
testcase_40 AC 341 ms
103,576 KB
testcase_41 AC 305 ms
89,664 KB
testcase_42 AC 646 ms
117,888 KB
testcase_43 AC 131 ms
78,540 KB
testcase_44 AC 802 ms
123,660 KB
testcase_45 AC 308 ms
88,400 KB
testcase_46 AC 529 ms
115,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    input = sys.stdin.readline

    class SegmentTree:
        def __init__(self, A, initialize=True, segfunc=max, ident=-2000000000):
            self.N = len(A)
            self.LV = (self.N - 1).bit_length()
            self.N0 = 1 << self.LV
            self.segfunc = segfunc
            self.ident = ident
            if initialize:
                self.data = [self.ident] * self.N0 + A + [self.ident] * (self.N0 - self.N)
                for i in range(self.N0 - 1, 0, -1):
                    self.data[i] = segfunc(self.data[i * 2], self.data[i * 2 + 1])
            else:
                self.data = [self.ident] * (self.N0 * 2)

        def update(self, i, x):
            i += self.N0 - 1
            self.data[i] = x
            for _ in range(self.LV):
                i >>= 1
                self.data[i] = self.segfunc(self.data[i * 2], self.data[i * 2 + 1])

        def get(self, i):
            return self.data[i + self.N0 - 1]

        # open interval [l, r)
        def query(self, l, r):
            l += self.N0 - 1
            r += self.N0 - 1
            ret_l = self.ident
            ret_r = self.ident
            while l < r:
                if l & 1:
                    ret_l = self.segfunc(ret_l, self.data[l])
                    l += 1
                if r & 1:
                    ret_r = self.segfunc(self.data[r - 1], ret_r)
                    r -= 1
                l >>= 1
                r >>= 1
            return self.segfunc(ret_l, ret_r)

        # return smallest i(l <= i < r) s.t. check(A[i]) == True
        def binsearch(self, l, r, check):
            if not check(self.query(l, r)):
                return r
            l += self.N0 - 1
            val = self.ident
            while True:
                if check(self.segfunc(val, self.data[l])):
                    break
                if l & 1:
                    val = self.segfunc(val, self.data[l])
                    l += 1
                l >>= 1
            while l < self.N0:
                newval = self.segfunc(val, self.data[l * 2])
                if not check(newval):
                    val = newval
                    l = (l << 1) + 1
                else:
                    l <<= 1
            return l - self.N0 + 1

    H, W, N, P = map(int, input().split())

    XY = []
    X_set = set()
    for _ in range(N):
        x, y = map(int, input().split())
        XY.append((x, y))
        X_set.add(x)

    X_sorted = sorted(list(X_set))
    x2i = {x: i+1 for i, x in enumerate(X_sorted)}
    L = len(X_sorted)
    ST = SegmentTree([0] * L)
    XY.sort(key=lambda z: z[0])
    XY.sort(key=lambda z: z[1])
    for x, y in XY:
        i = x2i[x]
        ST.update(i, ST.query(1, i+1) + 1)
    ma = ST.query(1, L+1)
    ma = max(ma, 0)
    invP = pow(P, mod - 2, mod)
    ans = (1 - (pow(P - 2, ma, mod) * pow(P - 1, H + W - 3 - ma, mod) * pow(invP, H + W - 3, mod)) % mod) % mod
    print(ans)


if __name__ == '__main__':
    main()
0