結果

問題 No.2512 Mountain Sequences
ユーザー kemunikukemuniku
提出日時 2023-09-07 00:04:06
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,728 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 101,608 KB
最終ジャッジ日時 2023-09-07 00:24:54
合計ジャッジ時間 7,525 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 232 ms
90,336 KB
testcase_01 AC 227 ms
90,540 KB
testcase_02 AC 231 ms
89,756 KB
testcase_03 AC 224 ms
90,440 KB
testcase_04 AC 227 ms
90,360 KB
testcase_05 AC 223 ms
89,784 KB
testcase_06 AC 240 ms
90,572 KB
testcase_07 AC 233 ms
90,492 KB
testcase_08 AC 226 ms
89,824 KB
testcase_09 AC 224 ms
90,048 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 #

import io,os,sys

#https://recruit.gmo.jp/engineer/jisedai/blog/python_standard_io_with_bytesio/
buf = io.BytesIO()
def main():
    max_K = 5*10**5
    MOD = 998244353
    fact    =[-1] * (max_K+1) #MOD下での階乗
    inv     =[-1] * (max_K+1) #MOD下での逆元
    fact_inv=[-1] * (max_K+1) #MOD下での階乗の逆元
    fact[0]=fact[1]=1
    inv[1] = 1
    fact_inv[0]=fact_inv[1] = 1
    for i in range(2,max_K+1):
        fact[i] = (fact[i-1]*i)%MOD
        inv[i] = (-inv[MOD%i]*(MOD//i))%MOD
        fact_inv[i] = (fact_inv[i-1]*inv[i])%MOD
    def c(n,r):
        if n < 0 or r < 0 or r > n:
            return 0
        return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
    T = int(input())
    block = 972
    Qli = [[] for i in range(200001//block+1)]
    for i in range(T):
        l,r = map(int,input().split())
        Qli[l//block].append(r*(200001)*(200001)+l*(200001)+i)
    l = 0
    r = 0
    ans = 0
    answers = [0]*T
    f = 0
    f2 = fact_inv[2]
    for li in Qli:
        if len(li)==0:
            continue
        for x in sorted(li,reverse = f):
            R = x//((200001)*(200001))
            L = x//(200001)-R*(200001)
            i = x%(200001)
            while l > L:
                l -= 1
                ans =(c(2*r, l+1) - 2*ans)%MOD
            while l < L:
                ans = ((c(2*r, l+1) - ans) * fact_inv[2])%MOD
                l += 1
            while r > R:
                ans =( ans - c(2*r-2, l-1))%MOD
                r -= 1
            while r < R:
                r += 1
                ans = (ans + c(2*r-2, l-1))%MOD
            answers[i] = ans
        f^=1
    print(*answers,sep="\n")
main()
0