結果

問題 No.1349 Subset Product Queries
ユーザー gew1fw
提出日時 2025-06-12 21:31:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,666 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 157,012 KB
最終ジャッジ日時 2025-06-12 21:32:31
合計ジャッジ時間 4,998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 WA * 2 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    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
    prefix_zero = [0]*(N+1)
    for i in range(1, N+1):
        prefix_zero[i] = prefix_zero[i-1] + (1 if A[i-1] % P == 0 else 0)
    
    for _ in range(Q):
        L = int(input[idx]); idx +=1
        R = int(input[idx]); idx +=1
        K = int(input[idx]); idx +=1
        
        if K == 0:
            if prefix_zero[R] - prefix_zero[L-1] > 0:
                print("Yes")
            else:
                print("No")
            continue
        
        found = False
        for i in range(L-1, R):
            if A[i] % P == K % P:
                found = True
                break
        if found:
            print("Yes")
            continue
        
        current = set()
        target = K % P
        found = False
        for i in range(L-1, R):
            a = A[i] % P
            if a == 0:
                continue
            temp = set()
            temp.add(a)
            if a == target:
                found = True
                break
            for s in current:
                prod = (s * a) % P
                if prod == target:
                    found = True
                    break
                temp.add(prod)
            if found:
                break
            current.update(temp)
            if target in current:
                found = True
                break
        if found:
            print("Yes")
        else:
            print("No")

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