結果

問題 No.1349 Subset Product Queries
ユーザー LyricalMaestro
提出日時 2025-05-24 12:40:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,168 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 125,640 KB
最終ジャッジ日時 2025-05-24 12:41:10
合計ジャッジ時間 19,889 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1349


def main():
    N, Q, P = map(int, input().split())
    A = list(map(int, input().split()))
    lrk = []
    for _ in range(Q):
        l, r, k = map(int, input().split())
        lrk.append((l - 1, r - 1, k))
    
    r_array = [[] for _ in range(N)]
    for i in range(Q):
        l, r, k = lrk[i]
        r_array[r].append((i, l, k))

    answer = [-1] * Q
    max_left_index = [-1] * P
    for r in range(N):
        a = A[r]

        new_max_left_index = max_left_index.copy()
        for p in range(P):
            if max_left_index[p] == -1:
                continue

            new_key = (a * p) % P
            new_max_left_index[new_key] = max(new_max_left_index[new_key], max_left_index[p])
        
        new_max_left_index[a] = max(new_max_left_index[a], r)
        max_left_index = new_max_left_index

        for index, l, k in r_array[r]:
            x = max_left_index[k]
            if x >= l:
                answer[index] = True
            else:
                answer[index] = False
    
    for i in range(Q):
        if answer[i]:
            print("Yes")
        else:
            print("No")




                
                



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