結果

問題 No.2512 Mountain Sequences
ユーザー 👑 seekworserseekworser
提出日時 2023-09-06 20:13:17
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,699 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 157,348 KB
最終ジャッジ日時 2023-09-07 00:23:15
合計ジャッジ時間 13,516 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 787 ms
151,840 KB
testcase_01 AC 793 ms
151,636 KB
testcase_02 AC 791 ms
151,684 KB
testcase_03 AC 803 ms
151,464 KB
testcase_04 AC 798 ms
151,492 KB
testcase_05 AC 795 ms
151,728 KB
testcase_06 AC 784 ms
151,432 KB
testcase_07 AC 794 ms
151,880 KB
testcase_08 AC 808 ms
151,792 KB
testcase_09 AC 799 ms
151,900 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

block = 500
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 cmp(x, y):
#     xb = x[0] // block
#     yb = y[0] // block
#     if xb > yb:
#         return 1
#     elif xb < yb:
#         return -1
#     sign = xb % 2 == 0
#     if sign ^ (x[1] > y[1]):
#         return -1
#     else:
#         return 1
def c(n, r):
    if n < 0 or r < 0 or r > n:
        return 0
    return fact[n] * facti[r] * facti[n-r] % 998244353
# query.sort(key=cmp_to_key(cmp))
answer = [0] * t
ans = 1
l = 1
r = 1
modlim = 10 ** 15
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
            # if ans > modlim:
            #     ans %= 998244353
        while l < L:
            ans = (c(2*r, l+1) - ans) * facti[2]
            l += 1
            # if ans > modlim:
            #     ans %= 998244353
        while r > R:
            ans = ans - c(2*r-2, l-1)
            r -= 1
            # if ans > modlim:
            #     ans %= 998244353
        while r < R:
            r += 1
            ans = ans + c(2*r-2, l-1)
            # if ans > modlim:
            #     ans %= 998244353
        ans %= 998244353
        answer[id] = str(ans)
print("\n".join(answer))
0