結果

問題 No.3565 Take from Excluded
コンテスト
ユーザー kidodesu
提出日時 2026-06-05 22:26:52
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
RE  
実行時間 -
コード長 1,738 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 132 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 99,328 KB
最終ジャッジ日時 2026-06-05 22:27:20
合計ジャッジ時間 5,982 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 RE * 6 TLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

mod = 998244353
def main():
    n, q = list(map(int, input().split()))
    A = list(set(map(int, input().split())))
    A.sort()
    A = [(A[i], A[i]+1) for i in range(n)]
    for _ in range(q):
        k, x, m = list(map(int, input().split()))
        #print(A)
        while k and 1 < len(A):
            B = []
            s = m
            i = 1
            t = 0
            while s:
                if i == len(A):
                    B.append((A[i-1][1], A[i-1][1]+s))
                    s = 0
                elif A[i][0] == A[i-1][1]:
                    t += A[i][1]-A[i][0]
                    i += 1
                else:
                    ms = min(s, A[i][0]-A[i-1][1])
                    B.append((A[i-1][1], A[i-1][1]+ms))
                    s -= ms
                    if s:
                        t += A[i][1]-A[i][0]
                    i += 1
            A = B
            k -= 1
            if t < m and not k % 2:
                break
        if k and len(A) == 1:
            l, r = A[0]
            A = [(r+m*(k-1), r+m*k)]
            print((A[0][0]+x-1)%mod)
        else:
            if k:
                k //= 2
                c = len(A)
                off = 2*m*(k//c)
                k %= c
                B = []
                for i in range(k, k+c):
                    i %= c
                    l, r = A[i]
                    if k <= i:
                        B.append((l+off, r+off))
                    else:
                        B.append((l+off+2*m, r+off+2*m))
                A = B
            s = x
            for l, r in A:
                ms = min(r-l, s)
                s -= ms
                if s == 0:
                    print((l+ms-1)%mod)
                    break
main()
0