結果

問題 No.2230 Good Omen of White Lotus
ユーザー shobonvip
提出日時 2023-02-24 22:32:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 726 ms / 2,000 ms
コード長 1,926 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 180,532 KB
最終ジャッジ日時 2024-09-13 05:46:37
合計ジャッジ時間 14,102 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
	def __init__(self, n):
		tmp = 0
		while n != 0:
			n >>= 1
			tmp += 1
		self.seglen = 1 << tmp
		self.inf = 0
		self.seg = [self.inf]*(self.seglen*2)
	
	def update(self, x, val):
		# update x to val;
		x += self.seglen
		self.seg[x] = val
		while x > 1:
			x >>= 1
			self.seg[x] = max(self.seg[2*x], self.seg[2*x+1])
	
	def allupdate(self, a):
		targ = self.seglen
		for i in range(len(a)):
			self.seg[targ + i] = a[i]
		for i in range(self.seglen-1, -1, -1):
			self.seg[i] = max(self.seg[2*i], self.seg[2*i+1])

	def query(self, l, r):
		l = max(l, 0) + self.seglen
		r = max(r, 0) + self.seglen
		lres, rres = self.inf, self.inf
		while l < r:
			if l & 1:
				lres = max(lres, self.seg[l])
				l += 1
			if r & 1:
				r -= 1
				rres = max(rres, self.seg[r])
			l >>= 1
			r >>= 1
		return max(lres, rres)

def compress(arr):
	*XS, = set(arr)
	XS.sort()
	return {cmp_e: cmp_i for cmp_i, cmp_e in enumerate(XS)}

h,w,n,p = map(int,input().split())
ys = []
bucket = [[] for i in range(h)]
for i in range(n):
	x, y = map(int,input().split())
	bucket[x-1].append(y-1)
	ys.append(y-1)
y_c = compress(ys)
m = len(y_c)

seg = SegmentTree(m)
for i in range(h):
	bucket[i].sort()
	for j in bucket[i]:
		targ = y_c[j]
		ast = seg.query(0, targ+1) + 1
		ar = seg.query(targ, targ + 1)
		seg.update(targ, max(ar, ast))

tmp = seg.query(0, m)

mod = 998244353
yes = (1 - 2 * pow(p, mod-2, mod)) % mod
no = (1 - pow(p, mod-2, mod)) % mod

def best_fraction(n:int, mod:int, strmode=0) -> tuple:
	w = 9 * 10 ** 18
	t = pow(n, mod-2, mod)
	ansx, ansy = 0, 0
	for b in range(1, mod):
		if b*b > w: break
		a = n*b % mod
		c = t*b % mod
		if a*b < w:
			w = a*b
			ansx, ansy = a, b
		if c*b < w:
			w = c*b
			ansx, ansy = b, c
	if strmode:
		return f"{n} = {ansx}/{ansy} (mod {mod})"
	return (ansx, ansy)


ans = (1 - pow(yes, tmp, mod) * pow(no, h+w-3-tmp, mod)) % mod
print(ans)
#print(best_fraction(ans, mod, 1))
0