結果
問題 | No.2758 RDQ |
ユーザー | rlangevin |
提出日時 | 2024-05-17 21:27:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,083 ms / 2,000 ms |
コード長 | 2,492 bytes |
コンパイル時間 | 220 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 235,668 KB |
最終ジャッジ日時 | 2024-05-17 23:43:09 |
合計ジャッジ時間 | 12,320 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 312 ms
111,524 KB |
testcase_01 | AC | 62 ms
71,772 KB |
testcase_02 | AC | 60 ms
71,780 KB |
testcase_03 | AC | 61 ms
71,964 KB |
testcase_04 | AC | 61 ms
71,804 KB |
testcase_05 | AC | 62 ms
70,932 KB |
testcase_06 | AC | 987 ms
231,144 KB |
testcase_07 | AC | 915 ms
235,668 KB |
testcase_08 | AC | 1,083 ms
230,764 KB |
testcase_09 | AC | 1,073 ms
231,908 KB |
testcase_10 | AC | 909 ms
231,492 KB |
testcase_11 | AC | 468 ms
115,196 KB |
testcase_12 | AC | 466 ms
115,036 KB |
testcase_13 | AC | 470 ms
114,564 KB |
testcase_14 | AC | 447 ms
114,400 KB |
testcase_15 | AC | 456 ms
114,352 KB |
testcase_16 | AC | 448 ms
113,960 KB |
testcase_17 | AC | 451 ms
115,284 KB |
testcase_18 | AC | 477 ms
114,504 KB |
testcase_19 | AC | 514 ms
114,660 KB |
testcase_20 | AC | 441 ms
115,332 KB |
testcase_21 | AC | 63 ms
72,644 KB |
testcase_22 | AC | 59 ms
71,268 KB |
testcase_23 | AC | 60 ms
71,664 KB |
ソースコード
class Divisor(): def __init__(self, N): self.L = list(range(N + 1)) for i in range(2, N + 1): if i != self.L[i]: continue for j in range(2 * i, N + 1, i): self.L[j] = i def factorize(self, n): if n <= 1: return [] D = [] while n != 1: cnt = 0 now = self.L[n] while n % now == 0: cnt += 1 n //= now D.append((now, cnt)) return D def div(self, n): A = self.factorize(n) now = [1] for k, v in A: M = len(now) for i in range(M): x = now[i] for _ in range(v): x *= k now.append(x) return now class Fenwick_Tree: def __init__(self, n): self._n = n self.data = [0] * n def add(self, p, x): assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def sum(self, l, r): assert 0 <= l <= r <= self._n return self._sum(r) - self._sum(l) def _sum(self, r): s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s # T.sum(0, x) <= kとなる最大のxを返す。 def get(self, k): k += 1 x, r = 0, 1 while r < self._n: r <<= 1 len = r while len: if x + len - 1 < self._n: if self.data[x + len - 1] < k: k -= self.data[x + len - 1] x += len len >>= 1 return x def __str__(self): temp = [] for i in range(self._n): temp.append(str(self.sum(i, i + 1))) return ' '.join(temp) N, Q = map(int, input().split()) A = list(map(int, input().split())) M = 10 ** 5 + 5 T = Fenwick_Tree(M) query = [[] for _ in range(M)] for i in range(Q): L, R, K = map(int, input().split()) query[K].append((L - 1, R, i)) D = Divisor(M) L = [[] for i in range(M)] for i, a in enumerate(A): for d in D.div(a): L[d].append(i) ans = [-1] * Q for i in range(M): if not query[i]: continue for j in L[i]: T.add(j, 1) for l, r, ind in query[i]: ans[ind] = T.sum(l, r) for j in L[i]: T.add(j, -1) for a in ans: print(a)