結果

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

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

def nec(X,k):
    ko=k
    Y=[]
    for i in range(len(X)):
        a,b=X[i]

        if i+1<len(X):
            c,d=X[i+1]
        else:
            c,d=1<<63,1<<63

        minus=c-(a+b)

        MIN=min(ko,minus)
        ko-=MIN

        Y.append([a+b,MIN])

        if ko==0:
            break
    return Y

def what(X,x):
    for i in range(len(X)):
        a,b=X[i]
        if b>=x:
            return a+(x-1)
        else:
            x-=b
    

def kai(X,k,m):
    if k%2==1:
        X=nec(X,m)
        k-=1

    necfirst=X[-1][0]+X[-1][1]
    first=X[0][0]

    Y=[]
    for a,b in X:
        Y.append([a+(necfirst-first),b])

    X=X+Y

    return X[k:k+len(X)//2]

    

mod=998244353

N,Q=list(map(int,input().split()))
A=list(map(int,input().split()))
A=sorted(set(A))

X=[]
for a in A:
    if X==[] or X[-1][0]+X[-1][1]!=a:
        X.append([a,1])
    else:
        X[-1][1]+=1

#print(X)

plus=0
for tests in range(Q):
    k,x,m=list(map(int,input().split()))

    if k<=5:

        for tt in range(k):
            X=nec(X,m)

        print((what(X,x)+plus)%mod)
    else:
        #print("!",X)
        Y=nec(X,m)
        Z=nec(Y,m)
        k-=1

        while len(Y)!=len(Z):
            Y=Z
            Z=nec(Y,m)
            k-=1
            

        #print(Y)
        #print(Z)

        LEN=len(Y)+len(Z)

        a,b=Z[-1]
        necfirst=a+b
        first=Y[0][0]

        shuuki=necfirst-first


        rep=k//(LEN)
        k%=(LEN)
        plus=(plus+shuuki*rep)%mod

        Y=kai(Y,k,m)

        #print("!",Y1)

        #for tt in range(k):
        #    Y=nec(Y,m)

        #print("?",Y)


        X=Y
        if X[0][0]>=mod:
            k=X[0][0]//mod

            for i in range(len(X)):
                X[i][0]-=k*mod
        print((what(X,x)+plus)%mod)
        
        

        
0