結果
| 問題 |
No.2758 RDQ
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2024-05-18 01:03:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 730 ms / 2,000 ms |
| コード長 | 880 bytes |
| コンパイル時間 | 262 ms |
| コンパイル使用メモリ | 82,348 KB |
| 実行使用メモリ | 217,096 KB |
| 最終ジャッジ日時 | 2024-12-20 15:57:34 |
| 合計ジャッジ時間 | 12,452 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
from collections import defaultdict
from bisect import bisect_left, bisect_right
def divisors(n: int) -> list:
s = set()
p = 1
while p * p <= n:
if n % p == 0:
s.add(p)
s.add(n // p)
p += 1
return sorted(s)
def find_interval(a: list, lo: int, hi: int) -> tuple[int, int, int]:
assert lo <= hi
empty = 0, -1, -1 # 区間なし
if not a or lo > a[-1] or hi < a[0]: return empty
l = bisect_left(a, lo)
r = bisect_right(a, hi) - 1
if l > r: return empty
return r-l+1, l, r
N, Q = map(int, input().split())
A = list(map(int, input().split()))
d = defaultdict(list)
for i, a in enumerate(A):
for x in divisors(a):
d[x].append(i)
for _ in range(Q):
L, R, K = map(int, input().split())
L -= 1
R -= 1
t = d[K]
cnt, _, _ = find_interval(d[K], L, R)
print(cnt)
norioc