結果
問題 | No.1349 Subset Product Queries |
ユーザー |
![]() |
提出日時 | 2025-06-12 21:32:52 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,612 bytes |
コンパイル時間 | 353 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 173,696 KB |
最終ジャッジ日時 | 2025-06-12 21:34:01 |
合計ジャッジ時間 | 5,171 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 WA * 2 TLE * 1 -- * 19 |
ソースコード
import sys def main(): input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx +=1 Q = int(data[idx]) idx +=1 P = int(data[idx]) idx +=1 A = list(map(int, data[idx:idx+N])) idx += N # Precompute prefix sum of zeros 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(data[idx]) idx +=1 R = int(data[idx]) idx +=1 K = int(data[idx]) idx +=1 if K == 0: # Check if any zero in [L, R] if prefix_zero[R] - prefix_zero[L-1] > 0: print("Yes") else: print("No") continue # Check if any element in [L, R] is non-zero mod P has_non_zero = False for i in range(L-1, R): if A[i] % P != 0: has_non_zero = True break if not has_non_zero: print("No") continue # Process the subarray current = set() found = False for i in range(L-1, R): a = A[i] % P if a ==0: continue new_current = set() for r in current: new_r = (r * a) % P new_current.add(new_r) new_current.add(a) current.update(new_current) if K in current: found = True break print("Yes" if found else "No") if __name__ == "__main__": main()