結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | mkawa2 |
提出日時 | 2022-07-06 11:06:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,229 ms / 2,000 ms |
コード長 | 1,781 bytes |
コンパイル時間 | 315 ms |
コンパイル使用メモリ | 82,464 KB |
実行使用メモリ | 252,096 KB |
最終ジャッジ日時 | 2024-12-21 08:09:15 |
合計ジャッジ時間 | 23,429 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 856 ms
249,976 KB |
testcase_01 | AC | 623 ms
181,748 KB |
testcase_02 | AC | 771 ms
216,736 KB |
testcase_03 | AC | 195 ms
125,552 KB |
testcase_04 | AC | 318 ms
166,800 KB |
testcase_05 | AC | 36 ms
52,856 KB |
testcase_06 | AC | 34 ms
52,992 KB |
testcase_07 | AC | 344 ms
130,088 KB |
testcase_08 | AC | 283 ms
125,684 KB |
testcase_09 | AC | 614 ms
241,780 KB |
testcase_10 | AC | 655 ms
225,464 KB |
testcase_11 | AC | 632 ms
243,680 KB |
testcase_12 | AC | 592 ms
226,648 KB |
testcase_13 | AC | 711 ms
237,492 KB |
testcase_14 | AC | 729 ms
246,500 KB |
testcase_15 | AC | 676 ms
228,960 KB |
testcase_16 | AC | 681 ms
229,572 KB |
testcase_17 | AC | 691 ms
234,628 KB |
testcase_18 | AC | 55 ms
67,696 KB |
testcase_19 | AC | 56 ms
68,628 KB |
testcase_20 | AC | 57 ms
70,524 KB |
testcase_21 | AC | 58 ms
70,448 KB |
testcase_22 | AC | 674 ms
227,800 KB |
testcase_23 | AC | 517 ms
178,820 KB |
testcase_24 | AC | 687 ms
233,108 KB |
testcase_25 | AC | 635 ms
213,268 KB |
testcase_26 | AC | 660 ms
225,724 KB |
testcase_27 | AC | 37 ms
52,552 KB |
testcase_28 | AC | 35 ms
52,376 KB |
testcase_29 | AC | 36 ms
52,584 KB |
testcase_30 | AC | 36 ms
52,396 KB |
testcase_31 | AC | 50 ms
62,860 KB |
testcase_32 | AC | 50 ms
62,856 KB |
testcase_33 | AC | 38 ms
53,004 KB |
testcase_34 | AC | 61 ms
62,600 KB |
testcase_35 | AC | 38 ms
52,464 KB |
testcase_36 | AC | 36 ms
52,872 KB |
testcase_37 | AC | 37 ms
52,664 KB |
testcase_38 | AC | 1,229 ms
252,096 KB |
testcase_39 | AC | 791 ms
251,704 KB |
testcase_40 | AC | 512 ms
178,940 KB |
testcase_41 | AC | 852 ms
251,968 KB |
testcase_42 | AC | 842 ms
251,820 KB |
testcase_43 | AC | 856 ms
251,964 KB |
testcase_44 | AC | 877 ms
251,956 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = (1 << 63)-1 inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 class SparseTable: def __init__(self, op, e, aa): self.op = op w = len(aa) h = w.bit_length() table = [aa]+[[e() for _ in range(w)] for _ in range(h-1)] tablei1 = table[0] for i in range(1, h): tablei = table[i] for j in range(w-(1 << i)+1): rj = j+(1 << (i-1)) tablei[j] = op(tablei1[j], tablei1[rj]) tablei1 = tablei self.table = table # [l,r)の取得 def prod(self, l, r): i = (r-l).bit_length()-1 tablei = self.table[i] return self.op(tablei[l], tablei[r-(1 << i)]) from math import gcd def binary_search(l, r, ok, minimize): if minimize: l -= 1 else: r += 1 while l+1 < r: m = (l+r)//2 if ok(m) ^ minimize: l = m else: r = m if minimize: return r return l def ok(m): return sp.prod(m, i+1) > 1 n = II() aa = LI() sp = SparseTable(gcd, int, aa) ans = 0 for i in range(n): j = binary_search(0, i+1, ok, True) ans += j print(ans)