結果

問題 No.2512 Mountain Sequences
ユーザー 👑 seekworserseekworser
提出日時 2023-09-06 20:30:07
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,234 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 153,020 KB
最終ジャッジ日時 2023-09-07 00:24:12
合計ジャッジ時間 45,843 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 769 ms
152,408 KB
testcase_01 AC 648 ms
152,156 KB
testcase_02 AC 652 ms
152,316 KB
testcase_03 AC 657 ms
152,304 KB
testcase_04 AC 659 ms
152,308 KB
testcase_05 AC 654 ms
151,948 KB
testcase_06 AC 649 ms
152,024 KB
testcase_07 AC 653 ms
152,200 KB
testcase_08 AC 653 ms
152,196 KB
testcase_09 AC 654 ms
152,504 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 1,443 ms
152,696 KB
testcase_21 AC 1,438 ms
152,372 KB
testcase_22 AC 1,451 ms
152,404 KB
testcase_23 AC 1,483 ms
152,612 KB
testcase_24 AC 1,480 ms
152,532 KB
testcase_25 AC 757 ms
152,464 KB
testcase_26 AC 763 ms
153,016 KB
testcase_27 AC 783 ms
152,392 KB
testcase_28 AC 1,374 ms
152,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cmp_to_key
from sys import stdin
input = stdin.readline

mod = 998244353
fact = [1]
mx = 5 * 10 ** 5 + 1
for i in range(1, mx):
    fact.append(fact[-1] * i % mod)
facti = []
for f in fact:
    facti.append(pow(f, mod-2, mod))

block = 450
t = int(input())
query = [[] for _ in range(2 * 10 ** 5 // block + 1)]
for i in range(t):
    n,m = map(int,input().split())
    query[n // block].append([m,n,i])
def c(n, r):
    if n < 0 or r < 0 or r > n:
        return 0
    return (fact[n] * facti[r] % mod) * facti[n-r] % mod
# query.sort(key=cmp_to_key(cmp))
answer = [0] * t
ans = 1
l = 1
r = 1
for i in range(len(query)):
    if not query[i]:
        continue
    query[i].sort(reverse=(i%2 == 1))
    for qi in query[i]:
        R, L, id = qi
        while l > L:
            l -= 1
            ans = c(2*r, l+1) - 2*ans
            ans %= mod
        while l < L:
            ans = (c(2*r, l+1) - ans) * facti[2]
            l += 1
            ans %= mod
        while r > R:
            ans = ans - c(2*r-2, l-1)
            r -= 1
            ans %= mod
        while r < R:
            r += 1
            ans = ans + c(2*r-2, l-1)
            ans %= mod
        answer[id] = str(ans)
print("\n".join(answer))
0