結果
| 問題 |
No.1349 Subset Product Queries
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 21:32:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,283 bytes |
| コンパイル時間 | 249 ms |
| コンパイル使用メモリ | 82,284 KB |
| 実行使用メモリ | 142,852 KB |
| 最終ジャッジ日時 | 2025-06-12 21:33:50 |
| 合計ジャッジ時間 | 5,050 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 TLE * 1 -- * 19 |
ソースコード
def main():
import sys
input = sys.stdin.read().split()
ptr = 0
N = int(input[ptr])
ptr += 1
Q = int(input[ptr])
ptr += 1
P = int(input[ptr])
ptr += 1
A = list(map(int, input[ptr:ptr + N]))
ptr += N
output = []
for _ in range(Q):
L = int(input[ptr])
ptr += 1
R = int(input[ptr])
ptr += 1
K = int(input[ptr])
ptr += 1
if K == 0:
has_zero = False
for i in range(L-1, R):
if A[i] == 0:
has_zero = True
break
if has_zero:
output.append("Yes")
continue
current_bits = 0
found = False
for i in range(L-1, R):
a = A[i]
if a == 0:
continue
temp = current_bits
new_bits = 0
for r in range(P):
if (temp >> r) & 1:
new_r = (r * a) % P
new_bits |= 1 << new_r
new_bits |= 1 << a
current_bits |= new_bits
if (current_bits >> 0) & 1:
found = True
break
if found or (current_bits & 1):
output.append("Yes")
else:
output.append("No")
else:
current_bits = 0
found = False
for i in range(L-1, R):
a = A[i]
if a == 0:
continue
if a == K:
found = True
break
temp = current_bits
new_bits = 0
for r in range(P):
if (temp >> r) & 1:
new_r = (r * a) % P
new_bits |= 1 << new_r
new_bits |= 1 << a
current_bits |= new_bits
if (current_bits >> K) & 1:
found = True
break
if found:
output.append("Yes")
else:
output.append("No")
print('\n'.join(output))
if __name__ == '__main__':
main()
gew1fw