結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | mkawa2 |
提出日時 | 2022-07-06 11:06:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,266 ms / 2,000 ms |
コード長 | 1,781 bytes |
コンパイル時間 | 379 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 252,212 KB |
最終ジャッジ日時 | 2024-06-01 05:11:27 |
合計ジャッジ時間 | 26,349 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 910 ms
250,420 KB |
testcase_01 | AC | 656 ms
181,856 KB |
testcase_02 | AC | 798 ms
216,644 KB |
testcase_03 | AC | 212 ms
125,380 KB |
testcase_04 | AC | 328 ms
167,064 KB |
testcase_05 | AC | 39 ms
53,248 KB |
testcase_06 | AC | 40 ms
53,696 KB |
testcase_07 | AC | 361 ms
130,232 KB |
testcase_08 | AC | 297 ms
125,540 KB |
testcase_09 | AC | 644 ms
242,124 KB |
testcase_10 | AC | 693 ms
225,684 KB |
testcase_11 | AC | 658 ms
243,864 KB |
testcase_12 | AC | 603 ms
226,988 KB |
testcase_13 | AC | 743 ms
237,392 KB |
testcase_14 | AC | 760 ms
246,728 KB |
testcase_15 | AC | 704 ms
229,152 KB |
testcase_16 | AC | 710 ms
229,632 KB |
testcase_17 | AC | 730 ms
234,232 KB |
testcase_18 | AC | 60 ms
68,964 KB |
testcase_19 | AC | 61 ms
69,992 KB |
testcase_20 | AC | 64 ms
71,616 KB |
testcase_21 | AC | 63 ms
72,624 KB |
testcase_22 | AC | 697 ms
227,768 KB |
testcase_23 | AC | 528 ms
179,392 KB |
testcase_24 | AC | 727 ms
232,960 KB |
testcase_25 | AC | 664 ms
213,608 KB |
testcase_26 | AC | 693 ms
225,844 KB |
testcase_27 | AC | 41 ms
53,184 KB |
testcase_28 | AC | 42 ms
53,768 KB |
testcase_29 | AC | 40 ms
53,492 KB |
testcase_30 | AC | 40 ms
53,700 KB |
testcase_31 | AC | 51 ms
64,328 KB |
testcase_32 | AC | 53 ms
63,388 KB |
testcase_33 | AC | 41 ms
54,072 KB |
testcase_34 | AC | 52 ms
62,712 KB |
testcase_35 | AC | 40 ms
52,588 KB |
testcase_36 | AC | 40 ms
52,516 KB |
testcase_37 | AC | 40 ms
53,348 KB |
testcase_38 | AC | 1,266 ms
251,928 KB |
testcase_39 | AC | 833 ms
252,104 KB |
testcase_40 | AC | 521 ms
179,008 KB |
testcase_41 | AC | 901 ms
252,212 KB |
testcase_42 | AC | 894 ms
251,956 KB |
testcase_43 | AC | 904 ms
251,988 KB |
testcase_44 | AC | 923 ms
252,032 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)