結果

問題 No.2230 Good Omen of White Lotus
ユーザー vwxyzvwxyz
提出日時 2023-03-12 15:29:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 735 ms / 2,000 ms
コード長 3,319 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 81,652 KB
実行使用メモリ 107,988 KB
最終ジャッジ日時 2023-10-18 10:38:14
合計ジャッジ時間 14,489 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,468 KB
testcase_01 AC 39 ms
53,468 KB
testcase_02 AC 39 ms
53,468 KB
testcase_03 AC 39 ms
53,468 KB
testcase_04 AC 38 ms
53,468 KB
testcase_05 AC 38 ms
53,468 KB
testcase_06 AC 39 ms
53,468 KB
testcase_07 AC 39 ms
53,468 KB
testcase_08 AC 39 ms
53,468 KB
testcase_09 AC 38 ms
53,468 KB
testcase_10 AC 40 ms
53,468 KB
testcase_11 AC 39 ms
53,468 KB
testcase_12 AC 40 ms
53,468 KB
testcase_13 AC 51 ms
61,644 KB
testcase_14 AC 215 ms
77,388 KB
testcase_15 AC 62 ms
67,968 KB
testcase_16 AC 280 ms
77,968 KB
testcase_17 AC 280 ms
77,968 KB
testcase_18 AC 278 ms
77,972 KB
testcase_19 AC 280 ms
77,968 KB
testcase_20 AC 122 ms
76,596 KB
testcase_21 AC 101 ms
76,212 KB
testcase_22 AC 120 ms
76,444 KB
testcase_23 AC 120 ms
76,456 KB
testcase_24 AC 62 ms
75,712 KB
testcase_25 AC 62 ms
75,712 KB
testcase_26 AC 64 ms
77,912 KB
testcase_27 AC 348 ms
107,928 KB
testcase_28 AC 323 ms
107,508 KB
testcase_29 AC 346 ms
97,860 KB
testcase_30 AC 352 ms
97,720 KB
testcase_31 AC 379 ms
107,988 KB
testcase_32 AC 379 ms
107,988 KB
testcase_33 AC 717 ms
101,992 KB
testcase_34 AC 691 ms
101,896 KB
testcase_35 AC 723 ms
101,600 KB
testcase_36 AC 681 ms
101,612 KB
testcase_37 AC 670 ms
101,600 KB
testcase_38 AC 735 ms
101,800 KB
testcase_39 AC 700 ms
102,120 KB
testcase_40 AC 327 ms
95,412 KB
testcase_41 AC 292 ms
82,468 KB
testcase_42 AC 483 ms
91,932 KB
testcase_43 AC 157 ms
86,496 KB
testcase_44 AC 635 ms
96,680 KB
testcase_45 AC 282 ms
83,952 KB
testcase_46 AC 434 ms
93,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

class Dual_Segment_Tree:
    def __init__(self,N,f_act,e_act,operate,lst):
        self.N=N
        self.f_act=f_act
        self.e_act=e_act
        self.operate=operate
        self.lst=[None]*self.N
        for i,x in enumerate(lst):
            self.lst[i]=x
        self.segment_tree_act=[self.e_act]*(self.N+self.N)

    def __getitem__(self,i):
        if type(i) is int:
            if -self.N<=i<0:
                i+=self.N*2
            elif 0<=i<self.N:
                i+=self.N
            else:
                raise IndexError("list index out of range")
            self.Propagate_Above(i)
            return self.Operate_At(i)
        else:
            a,b,c=i.start,i.stop,i.step
            if a==None or a<-self.N:
                a=0
            elif self.N<=a:
                a=self.N
            elif a<0:
                a+=self.N
            if b==None or self.N<=b:
                b=self.N
            elif b<-self.N:
                b=0
            elif b<0:
                b+=self.N
            return self.lst[slice(a,b,c)]

    def Operate_At(self,i):
        return self.operate(self.lst[i-self.N],self.segment_tree_act[i])

    def Propagate_At(self,i):
        self.segment_tree_act[i<<1]=self.f_act(self.segment_tree_act[i<<1],self.segment_tree_act[i])
        self.segment_tree_act[i<<1|1]=self.f_act(self.segment_tree_act[i<<1|1],self.segment_tree_act[i])
        self.segment_tree_act[i]=self.e_act

    def Propagate_Above(self,i):
        H=i.bit_length()-1
        for h in range(H,0,-1):
            self.Propagate_At(i>>h)

    def Operate_Range(self,a,L=None,R=None):
        if L==None:
            L=self.N
        else:
            L+=self.N
        if R==None:
            R=self.N*2
        else:
            R+=self.N
        L0=L//(L&-L)
        R0=R//(R&-R)-1
        self.Propagate_Above(L0)
        self.Propagate_Above(R0)
        while L<R:
            if L&1:
                self.segment_tree_act[L]=self.f_act(self.segment_tree_act[L],a)
                L+=1
            if R&1:
                R-=1
                self.segment_tree_act[R]=self.f_act(self.segment_tree_act[R],a)
            L>>=1
            R>>=1

    def Update(self):
        for i in range(1,self.N):
            self.Propagate_At(i)
            self.segment_tree_act[i]=self.e_act

    def __str__(self):
        import copy
        segment_tree_act=copy.deepcopy(self.segment_tree_act)
        for i in range(1,self.N):
            segment_tree_act[i<<1]=self.f_act(segment_tree_act[i<<1],segment_tree_act[i])
            segment_tree_act[i<<1|1]=self.f_act(segment_tree_act[i<<1|1],segment_tree_act[i])
            segment_tree_act[i]=self.e_act
            segment_tree_act[i]=self.e_act
        return "["+", ".join(map(str,[self.operate(x,a) for x,a in zip(self.lst,segment_tree_act[self.N:])]))+"]"

H,W,N,P=map(int,readline().split())
query=[[] for h in range(H)]
for n in range(N):
    x,y=map(int,readline().split())
    x-=1;y-=1
    query[x].append(y)
inf=1<<30
DST=Dual_Segment_Tree(W,max,-inf,max,[0]*W)
for h in range(H):
    query[h].sort()
    for w in query[h]:
        DST.Operate_Range(DST[w]+1,w)
cnt=DST[W-1]
mod=998244353
ans=1-pow(P-2,cnt,mod)*pow(P-1,H+W-3-cnt,mod)%mod*pow(P,(mod-2)*(H+W-3),mod)%mod
ans%=mod
print(ans)
0