結果

問題 No.1349 Subset Product Queries
ユーザー lam6er
提出日時 2025-03-31 17:28:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,145 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 82,652 KB
実行使用メモリ 314,292 KB
最終ジャッジ日時 2025-03-31 17:30:04
合計ジャッジ時間 5,194 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx]); idx += 1
    Q = int(input[idx]); idx += 1
    P = int(input[idx]); idx += 1
    A = list(map(int, input[idx:idx+N]))
    idx += N

    # Precompute multiplication table
    mult_table = [[0] * P for _ in range(P)]
    for a in range(P):
        for s in range(P):
            mult_table[a][s] = (s * a) % P

    output = []
    for _ in range(Q):
        L = int(input[idx]) - 1; idx += 1  # Convert to 0-based index
        R = int(input[idx]) - 1; idx += 1
        K = int(input[idx]); idx += 1

        # Slice the subarray
        sub_A = A[L:R+1]
        mask = 0
        for a in sub_A:
            new_part = 0
            temp = mask
            while temp:
                lsb = temp & -temp
                s = (lsb).bit_length() - 1
                new_part |= 1 << mult_table[a][s]
                temp ^= lsb
            mask = (mask | new_part) | (1 << a)

        if mask & (1 << K):
            output.append("Yes")
        else:
            output.append("No")

    print('\n'.join(output))

if __name__ == "__main__":
    main()
0