結果
| 問題 |
No.1349 Subset Product Queries
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:26:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,666 bytes |
| コンパイル時間 | 244 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 161,968 KB |
| 最終ジャッジ日時 | 2025-06-12 16:27:09 |
| 合計ジャッジ時間 | 4,863 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 WA * 2 TLE * 1 -- * 19 |
ソースコード
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()
gew1fw