結果
| 問題 | 
                            No.1864 Shortest Paths Counting
                             | 
                    
| コンテスト | |
| ユーザー | 
                             shobonvip
                         | 
                    
| 提出日時 | 2022-03-04 23:02:24 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 575 ms / 2,000 ms | 
| コード長 | 1,995 bytes | 
| コンパイル時間 | 1,925 ms | 
| コンパイル使用メモリ | 81,716 KB | 
| 実行使用メモリ | 136,200 KB | 
| 最終ジャッジ日時 | 2024-07-18 21:37:09 | 
| 合計ジャッジ時間 | 7,394 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 23 | 
ソースコード
# DIST a-b = 2X, a+b = 2Y として定める.
mod = 998244353
class BIT:
	"""
	<Attention> 0-indexed.
	query ... return the sum [0 to m]
	sum ... return the sum [a to b]
	sumall ... return the sum [all]
	add ... 'add' number to element (be careful that it doesn't set a value.)
	search ... the sum version of bisect.right
	output ... return the n-th element
	listout ... return the BIT list
	"""
	
	def query(self, m):
		res = 0
		while m > 0:
			res = (res+self.bit[m])%mod
			m -= m&(-m)
		return res
	
	def sum(self, a, b):
		return (self.query(b)-self.query(a))%mod
	
	def sumall(self):
		bitlen = self.bitlen-1
		return self.query(bitlen)
	
	def add(self, m, x):
		m += 1
		bitlen = len(self.bit)
		while m <= bitlen-1:
			self.bit[m] = (self.bit[m]+x)%mod
			m += m&(-m)
		return
	
	def output(self, a):
		return self.query(a+1)-self.query(a)
	
	def listout(self):
		return self.bit
	
	def __init__(self, a):
		self.bitlen = a+1
		self.bit = [0]*(a+1)
n = int(input())
a = []
sx, sy = 0, 0
gx, gy = 0, 0
for i in range(n):
	x, y = map(int, input().split())
	if i == 0:
		sx, sy = x + y, x - y
	elif i == n-1:
		gx, gy = x + y, x - y
	else:
		a.append((x + y, x - y))
#print(sx, sy, gx, gy)
if gx <= sx:
	sx, sy, gx, gy = gx, gy, sx, sy
ymin = min(sy, gy)
ymax = max(sy, gy)
b = []
c = []
def compress(arr):
	*XS, = set(arr)
	XS.sort()
	return {cmp_e:cmp_i for cmp_i, cmp_e in enumerate(XS)}
for i in range(n-2):
	if sx <= a[i][0] <= gx and ymin <= a[i][1] <= ymax:
		b.append((a[i][0], a[i][1]))
		c.append(a[i][1])
mode = 0
if sy <= gy:
	# increase
	mode = 1
c_cmp = compress(c)
# print(c)
# print(c_cmp)
#print(b)
# if
b.sort()
size = len(b)
dp = [0 for i in range(size+1)]
dp[0] = 1
bit = BIT(size+1)
ans = 0
if mode:
	bit.add(0, 1)
	for i in range(size):
		bit.add(c_cmp[b[i][1]]+1, bit.query(c_cmp[b[i][1]]+2))
	print(bit.sumall())
else:
	bit.add(size, 1)
	for i in range(size):
		bit.add(c_cmp[b[i][1]], bit.sum(c_cmp[b[i][1]], size+1))
	print(bit.sumall())
            
            
            
        
            
shobonvip