結果

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

ソースコード

diff #
raw source code

mod = 998244353
def main():
    n, q = list(map(int, input().split()))
    A = list(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]:
                    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:
            r = A[0][1]
            r = r + (k-1)*m
            A = [(r+m-1, r+m)]
            print((r+x-1)%mod)
            continue
        elif 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