結果
問題 | No.1864 Shortest Paths Counting |
ユーザー | wolgnik |
提出日時 | 2022-03-04 22:30:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 966 ms / 2,000 ms |
コード長 | 1,746 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 188,736 KB |
最終ジャッジ日時 | 2024-07-18 21:02:59 |
合計ジャッジ時間 | 17,790 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,608 KB |
testcase_01 | AC | 43 ms
52,352 KB |
testcase_02 | AC | 41 ms
52,480 KB |
testcase_03 | AC | 38 ms
52,352 KB |
testcase_04 | AC | 38 ms
52,352 KB |
testcase_05 | AC | 40 ms
52,736 KB |
testcase_06 | AC | 40 ms
52,352 KB |
testcase_07 | AC | 39 ms
51,968 KB |
testcase_08 | AC | 40 ms
52,480 KB |
testcase_09 | AC | 923 ms
188,540 KB |
testcase_10 | AC | 923 ms
188,416 KB |
testcase_11 | AC | 923 ms
188,556 KB |
testcase_12 | AC | 945 ms
188,420 KB |
testcase_13 | AC | 936 ms
188,736 KB |
testcase_14 | AC | 942 ms
188,204 KB |
testcase_15 | AC | 966 ms
188,436 KB |
testcase_16 | AC | 913 ms
187,996 KB |
testcase_17 | AC | 937 ms
188,264 KB |
testcase_18 | AC | 934 ms
188,492 KB |
testcase_19 | AC | 934 ms
187,856 KB |
testcase_20 | AC | 921 ms
188,040 KB |
testcase_21 | AC | 933 ms
188,536 KB |
testcase_22 | AC | 946 ms
187,928 KB |
testcase_23 | AC | 941 ms
188,192 KB |
testcase_24 | AC | 38 ms
52,480 KB |
testcase_25 | AC | 846 ms
142,360 KB |
testcase_26 | AC | 864 ms
188,480 KB |
ソースコード
import sys input = sys.stdin.readline N = int(input()) mod = 998244353 a = [] for _ in range(N): x, y = map(int, input().split()) a.append((x + y, x - y)) #print(a) def compress(init_val): t = sorted(set(init_val)) d = dict([[t[i], i] for i in range(len(t))]) res = [0] * len(init_val) for i in range(len(init_val)): res[i] = d[init_val[i]] return res def compress2(init_val): xs = compress([init_val[i][0] for i in range(len(init_val))]) ys = compress([init_val[i][1] for i in range(len(init_val))]) return [(xs[i], ys[i] + 1) for i in range(len(init_val))] a = compress2(a) s = min(a[0], a[-1]) t = max(a[0], a[-1]) a = sorted(a[1: -1]) class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) self.el = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.data[i] s %= mod i -= i & -i return s def add(self, i, x): self.el[i] += x self.el[i] %= mod while i <= self.n: self.data[i] += x self.data[i] %= mod i += i & -i def get(self, i, j = None): if j is None: return self.el[i] return (self.sum(j) - self.sum(i)) % mod def lowerbound(self, s): x = 0 y = 0 for i in range(self.n.bit_length(), -1, -1): k = x + (1 << i) if k <= self.n and (y + self.data[k] < s): y += self.data[k] x += 1 << i return x + 1 fwk = BIT(N) fwk.add(s[1], 1) #print(s, a, t) if s[1] <= t[1]: for x, y in a: if x in range(s[0], t[0] + 1) and y in range(s[1], t[1] + 1): fwk.add(y, fwk.sum(y)) print(fwk.sum(t[1])) else: for x, y in a: if x in range(s[0], t[0] + 1) and y in range(t[1], s[1] + 1): fwk.add(y, fwk.get(y - 1, N)) print(fwk.get(t[1] - 1, N))