結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー aaaaaaaaaa2230
提出日時 2022-03-22 22:43:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 988 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 360,320 KB
最終ジャッジ日時 2024-10-10 17:08:28
合計ジャッジ時間 9,469 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
from itertools import count

n,q = map(int,input().split())
A = list(map(int,input().split()))
Q = [list(map(int,input().split())) for i in range(q)]
A.sort()
mod = 998244353

dp = [[0]*(n+1) for i in range(n+1)]
dp[n][0] = 1
for i in range(n)[::-1]:
    a = A[i]
    for j in range(n+1):
        if dp[i+1][j] == 0:
            continue
        dp[i][j] += dp[i+1][j]*(a-1)%mod
        dp[i][j] %= mod
        dp[i][j+1] += dp[i+1][j]
        dp[i][j+1] %= mod

cumA = [1]
for a in A:
    cumA.append(cumA[-1]*a%mod)

for l,r,p in Q:
    ans = 0
    for i in range(l,r+1):
        ind = bisect.bisect_left(A,i)
        count = cumA[ind]*dp[ind][p]%mod
        ans ^= count
    print(ans%mod)
0