結果

問題 No.1864 Shortest Paths Counting
ユーザー 👑 rin204rin204
提出日時 2022-03-21 03:43:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 517 ms / 2,000 ms
コード長 1,645 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 109,324 KB
最終ジャッジ日時 2024-04-16 20:41:47
合計ジャッジ時間 7,587 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,352 KB
testcase_01 AC 37 ms
52,608 KB
testcase_02 AC 37 ms
52,608 KB
testcase_03 AC 39 ms
52,864 KB
testcase_04 AC 41 ms
52,864 KB
testcase_05 AC 41 ms
52,224 KB
testcase_06 AC 37 ms
52,224 KB
testcase_07 AC 37 ms
52,736 KB
testcase_08 AC 37 ms
52,224 KB
testcase_09 AC 229 ms
96,016 KB
testcase_10 AC 238 ms
96,268 KB
testcase_11 AC 223 ms
96,136 KB
testcase_12 AC 360 ms
106,516 KB
testcase_13 AC 209 ms
91,152 KB
testcase_14 AC 241 ms
97,036 KB
testcase_15 AC 282 ms
100,316 KB
testcase_16 AC 224 ms
96,012 KB
testcase_17 AC 277 ms
99,516 KB
testcase_18 AC 262 ms
97,932 KB
testcase_19 AC 225 ms
96,136 KB
testcase_20 AC 311 ms
102,148 KB
testcase_21 AC 201 ms
90,816 KB
testcase_22 AC 260 ms
98,320 KB
testcase_23 AC 235 ms
96,268 KB
testcase_24 AC 38 ms
52,864 KB
testcase_25 AC 517 ms
109,324 KB
testcase_26 AC 177 ms
91,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)

0