結果
問題 | No.1864 Shortest Paths Counting |
ユーザー |
![]() |
提出日時 | 2022-03-04 22:55:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,842 bytes |
コンパイル時間 | 145 ms |
コンパイル使用メモリ | 82,544 KB |
実行使用メモリ | 182,832 KB |
最終ジャッジ日時 | 2024-07-18 21:31:10 |
合計ジャッジ時間 | 16,438 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 WA * 16 |
ソースコード
mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x self.tree[i] %= mod i += i & -i def lower_bound(self, w): if w <= 0: return 0 x = 0 k = 1 << (self.size.bit_length() - 1) while k: if x + k <= self.size and self.tree[x + k] < w: w -= self.tree[x + k] x += k k >>= 1 return x + 1 N = int(input()) XY_ori = [] XY = [] for _ in range(N): x, y = map(int, input().split()) XY_ori.append((x, y)) XY.append((x + y, x - y)) if XY[0][0] > XY[-1][0]: XY = [(-x, y) for x, y in XY] if XY[0][1] > XY[-1][1]: XY = [(x, -y) for x, y in XY] XYI = [] Y = set() for i, xy in enumerate(XY): x, y = xy XYI.append((x, y, i)) Y.add(y) XYI.sort(key=lambda z: z[1]) XYI.sort(key=lambda z: z[0]) idx = {y: i + 1 for i, y in enumerate(sorted(list(Y)))} L = len(idx) bit = Bit(L) flg = 1 for x, y, i in XYI: if flg: if i != 0: continue else: flg = 0 bit.add(idx[y], 1) continue j = idx[y] a = bit.sum(j) if i == N - 1: print(a) break bit.add(j, a) if __name__ == '__main__': main()