結果

問題 No.2230 Good Omen of White Lotus
ユーザー flygonflygon
提出日時 2023-02-25 00:23:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 621 ms / 2,000 ms
コード長 2,312 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 86,728 KB
実行使用メモリ 130,204 KB
最終ジャッジ日時 2023-10-11 07:13:52
合計ジャッジ時間 16,977 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,024 KB
testcase_01 AC 77 ms
71,364 KB
testcase_02 AC 79 ms
71,252 KB
testcase_03 AC 77 ms
71,176 KB
testcase_04 AC 77 ms
71,124 KB
testcase_05 AC 77 ms
71,300 KB
testcase_06 AC 78 ms
71,224 KB
testcase_07 AC 79 ms
71,156 KB
testcase_08 AC 77 ms
71,364 KB
testcase_09 AC 77 ms
71,196 KB
testcase_10 AC 76 ms
71,064 KB
testcase_11 AC 77 ms
71,224 KB
testcase_12 AC 78 ms
71,012 KB
testcase_13 AC 81 ms
70,892 KB
testcase_14 AC 273 ms
92,040 KB
testcase_15 AC 96 ms
75,628 KB
testcase_16 AC 361 ms
100,376 KB
testcase_17 AC 356 ms
100,420 KB
testcase_18 AC 353 ms
100,152 KB
testcase_19 AC 354 ms
100,156 KB
testcase_20 AC 150 ms
78,956 KB
testcase_21 AC 124 ms
77,768 KB
testcase_22 AC 157 ms
79,976 KB
testcase_23 AC 155 ms
80,264 KB
testcase_24 AC 98 ms
83,388 KB
testcase_25 AC 97 ms
83,572 KB
testcase_26 AC 98 ms
83,436 KB
testcase_27 AC 390 ms
130,204 KB
testcase_28 AC 407 ms
125,752 KB
testcase_29 AC 423 ms
124,888 KB
testcase_30 AC 429 ms
124,972 KB
testcase_31 AC 447 ms
125,764 KB
testcase_32 AC 438 ms
125,652 KB
testcase_33 AC 621 ms
120,632 KB
testcase_34 AC 602 ms
120,640 KB
testcase_35 AC 621 ms
120,364 KB
testcase_36 AC 607 ms
120,324 KB
testcase_37 AC 598 ms
120,464 KB
testcase_38 AC 590 ms
120,532 KB
testcase_39 AC 594 ms
120,504 KB
testcase_40 AC 296 ms
99,484 KB
testcase_41 AC 254 ms
89,060 KB
testcase_42 AC 416 ms
106,704 KB
testcase_43 AC 169 ms
85,896 KB
testcase_44 AC 505 ms
113,244 KB
testcase_45 AC 263 ms
89,336 KB
testcase_46 AC 390 ms
105,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def add(x,y):
  return x + y

def e(a):
  if a == min:
    return 10**18
  if a == max:
    return -10**18
  if a == add:
    return 0

class SegTree:
  def __init__(self, segf, init_val):
    n = len(init_val)
    self.segf = segf
    self.e = e(segf)
    self.seg_len = 1 << n.bit_length()
    self.seg = [self.e] * 2*self.seg_len
    
    for i in range(n):
      self.seg[i+ self.seg_len] = init_val[i]
    for i in range(self.seg_len)[::-1]:
      self.seg[i] = segf(self.seg[i<<1], self.seg[i<<1|1])

  def point_add(self,pos,x):
    pos += self.seg_len
    self.seg[pos] += x 
    while True: 
      pos >>= 1 
      if not pos: break 
      self.seg[pos] = self.segf(self.seg[pos<<1],  self.seg[pos<<1|1])

  def point_update(self, pos, x):
    pos += self.seg_len
    self.seg[pos] = x 
    while True: 
      pos >>= 1 
      if not pos: break 
      self.seg[pos] = self.segf(self.seg[pos<<1],  self.seg[pos<<1|1])

  def get_range(self,l,r):
    l += self.seg_len; r += self.seg_len
    res = self.e
    while l < r: 
      if l & 1: 
        res = self.segf(res, self.seg[l])
        l += 1 
      if r & 1: 
        r -= 1 
        res = self.segf(res, self.seg[r])
      l >>= 1; r >>= 1
    return res
  
  # ------ range_add & get_point -------
  def range_add(self, l,r,x):
    l += self.seg_len; r += self.seg_len
    self.seg[l] += x
    self.seg[r] += x
    while l < r: 
      if l & 1: 
        self.seg[l] = self.segf(x,self.seg[l])
        l += 1 
      if r & 1: 
        r -= 1 
        self.seg[r] = self.segf(x,self.seg[r])
      l >>= 1; r >>= 1

  def get_point(self,pos):
    pos += self.seg_len
    res = self.seg[pos]
    while True: 
      pos >>=1
      if not pos: break
      res = self.segf(res, self.seg[pos])
    return res
  
mod = 998244353
h,w,n,p = map(int,input().split())
xy = [list(map(int,input().split())) for i in range(n)]
xx = [[] for i in range(h+1)]
for x,y in xy:
  xx[x].append(y)

for i in range(1, h+1):
  xx[i].sort()

st = SegTree(max, [0]*(w+1))

for i in range(1, h+1):
  xxi = xx[i]
  for y in xxi:
    tmp = st.get_range(0, y+1)
    tmp += 1
    st.point_update(y, tmp)
  
cnt = st.get_range(0, w+1)

ex1 = (p-1)*pow(p, mod-2, mod)
ex2 = (p-2)*pow(p, mod-2, mod)

ans = 1 - pow(ex1, h+w-1-cnt-2, mod) * pow(ex2, cnt, mod)%mod
ans %= mod
print(ans)
0