結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー tktk_snsntktk_snsn
提出日時 2022-04-30 10:22:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 730 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 360,476 KB
最終ジャッジ日時 2023-09-12 02:54:40
合計ジャッジ時間 9,512 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,456 KB
testcase_01 AC 80 ms
76,384 KB
testcase_02 AC 85 ms
76,272 KB
testcase_03 AC 74 ms
71,408 KB
testcase_04 AC 79 ms
76,100 KB
testcase_05 AC 81 ms
76,160 KB
testcase_06 AC 81 ms
76,316 KB
testcase_07 AC 83 ms
76,428 KB
testcase_08 AC 81 ms
76,064 KB
testcase_09 AC 78 ms
76,232 KB
testcase_10 AC 79 ms
76,412 KB
testcase_11 AC 462 ms
250,272 KB
testcase_12 AC 323 ms
181,540 KB
testcase_13 AC 584 ms
326,396 KB
testcase_14 AC 354 ms
204,268 KB
testcase_15 AC 207 ms
129,820 KB
testcase_16 AC 187 ms
112,592 KB
testcase_17 AC 110 ms
85,108 KB
testcase_18 AC 383 ms
220,304 KB
testcase_19 AC 387 ms
227,152 KB
testcase_20 AC 233 ms
133,808 KB
testcase_21 AC 730 ms
360,320 KB
testcase_22 AC 726 ms
360,228 KB
testcase_23 AC 730 ms
360,476 KB
testcase_24 AC 73 ms
71,464 KB
testcase_25 AC 74 ms
71,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 998244353


N, Q = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
prod = [1] * (N + 1)
for i, a in enumerate(A, 1):
    prod[i] = prod[i-1] * a % mod
A.reverse()
prod.reverse()

"""
dp[i,j]: i番目までみて、j個選んだ時の積の輪
"""
dp = [[0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i, a in enumerate(A, 1):
    for j in range(i):
        dp[i][j] += dp[i-1][j] * (a - 1)
        dp[i][j] %= mod
        dp[i][j+1] += dp[i-1][j]
        dp[i][j+1] %= mod

for _ in range(Q):
    L, R, P = map(int, input().split())

    res = 0
    i = 0
    for x in range(L, R+1)[::-1]:
        while i < N and A[i] >= x:
            i += 1
        cnt = dp[i][P] * prod[i] % mod
        res ^= cnt

    print(res % mod)
0