結果
| 問題 |
No.1864 Shortest Paths Counting
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-21 03:43:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 563 ms / 2,000 ms |
| コード長 | 1,645 bytes |
| コンパイル時間 | 217 ms |
| コンパイル使用メモリ | 81,840 KB |
| 実行使用メモリ | 108,544 KB |
| 最終ジャッジ日時 | 2024-10-07 23:54:03 |
| 合計ジャッジ時間 | 8,173 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
MOD = 998244353
class Bit:
def __init__(self, n):
self.size = n
self.n0 = 1 << (n.bit_length() - 1)
self.tree = [0] * (n + 1)
def range_sum(self, l, r):
return self.sum(r - 1) - self.sum(l - 1)
def sum(self, i):
i += 1
s = 0
while i > 0:
s += self.tree[i]
s %= MOD
i -= i & -i
return s
def get(self, i):
return self.sum(i) - self.sum(i - 1)
def add(self, i, x):
i += 1
while i <= self.size:
self.tree[i] += x
self.tree[i] %= MOD
i += i & -i
def lower_bound(self, x):
pos = 0
plus = self.n0
tot = 0
while plus > 0:
if pos + plus <= self.size and self.tree[pos + plus] < x:
x -= self.tree[pos + plus]
pos += plus
plus //= 2
return pos
n = int(input())
xy = []
for _ in range(n):
x, y = map(int, input().split())
xy.append((x - y, x + y))
if xy[0][0] < xy[-1][0]:
px = 1
else:
px = -1
if xy[0][1] < xy[-1][1]:
py = 1
else:
py = -1
xy = [(x * px, y * py) for x, y in xy]
sx, sy = xy[0]
gx, gy = xy[-1]
xy = xy[1:-1]
lst = []
se_y = {sy, gy}
for x, y in xy:
if sx <= x <= gx and sy <= y <= gy:
lst.append((x, y))
se_y.add(y)
lst.sort(key = lambda x:(x[0], x[1]))
dic = {y:i for i, y in enumerate(sorted(se_y))}
l = len(dic)
sy = dic[sy]
gy = dic[gy]
bit = Bit(l)
bit.add(sy, 1)
for _, y in lst:
y = dic[y]
bit.add(y, bit.sum(y))
ans = bit.sum(gy) % MOD
print(ans)