結果

問題 No.1036 Make One With GCD 2
ユーザー tamatotamato
提出日時 2020-04-24 22:38:58
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,746 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 246,748 KB
最終ジャッジ日時 2024-04-24 18:06:04
合計ジャッジ時間 38,417 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,400 ms
245,688 KB
testcase_01 AC 1,368 ms
222,944 KB
testcase_02 AC 897 ms
241,560 KB
testcase_03 AC 266 ms
106,624 KB
testcase_04 AC 480 ms
140,648 KB
testcase_05 AC 38 ms
52,480 KB
testcase_06 AC 36 ms
52,352 KB
testcase_07 AC 429 ms
135,236 KB
testcase_08 AC 352 ms
115,840 KB
testcase_09 AC 1,494 ms
219,616 KB
testcase_10 AC 1,378 ms
209,692 KB
testcase_11 AC 1,550 ms
222,128 KB
testcase_12 AC 1,392 ms
210,860 KB
testcase_13 AC 1,821 ms
233,912 KB
testcase_14 AC 1,653 ms
235,800 KB
testcase_15 AC 1,579 ms
226,024 KB
testcase_16 AC 1,596 ms
227,284 KB
testcase_17 AC 1,632 ms
231,304 KB
testcase_18 AC 67 ms
70,144 KB
testcase_19 AC 73 ms
71,168 KB
testcase_20 AC 76 ms
72,320 KB
testcase_21 AC 74 ms
72,192 KB
testcase_22 AC 1,535 ms
224,624 KB
testcase_23 AC 1,071 ms
165,900 KB
testcase_24 AC 1,556 ms
229,484 KB
testcase_25 AC 1,415 ms
216,580 KB
testcase_26 AC 1,493 ms
221,888 KB
testcase_27 AC 38 ms
52,352 KB
testcase_28 AC 38 ms
52,352 KB
testcase_29 AC 35 ms
52,352 KB
testcase_30 AC 34 ms
52,352 KB
testcase_31 AC 46 ms
61,184 KB
testcase_32 AC 52 ms
62,848 KB
testcase_33 AC 38 ms
52,736 KB
testcase_34 AC 48 ms
61,056 KB
testcase_35 AC 35 ms
52,480 KB
testcase_36 AC 42 ms
52,480 KB
testcase_37 AC 35 ms
52,224 KB
testcase_38 AC 811 ms
232,916 KB
testcase_39 AC 1,319 ms
240,716 KB
testcase_40 AC 1,067 ms
165,772 KB
testcase_41 TLE -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    # min
    def STfunc(a, b):
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        while a % b:
            a, b = b, a%b
        return b

    # クエリは0-indexedで[l, r)
    class SparseTable():
        def __init__(self, A):
            # A: 処理したい数列
            self.N = len(A)
            self.K = self.N.bit_length() - 1
            self.table = [[0] * (self.K + 1) for _ in range(self.N)]
            self.STfunc = STfunc
            for i, a in enumerate(A):
                self.table[i][0] = a
            for k in range(1, self.K + 1):
                for i in range(self.N):
                    j = i + (1 << (k - 1))
                    if j <= self.N - 1:
                        self.table[i][k] = self.STfunc(self.table[i][k - 1], self.table[j][k - 1])
                    # else:
                    #    self.table[i][k] = self.table[i][k-1]

        def query(self, l, r):
            # [l, r)の最小値を求める
            k = (r - l).bit_length() - 1
            return STfunc(self.table[l][k], self.table[r - (1 << k)][k])

    N = int(input())
    A = list(map(int, input().split()))

    ST = SparseTable(A)
    ans = 0
    for i in range(N):
        if A[i] == 1:
            ans += N - i
            continue
        if ST.query(i, N) != 1:
            continue
        ok = N-1
        ng = i
        mid = (ok + ng) // 2
        while ok - ng > 1:
            if ST.query(i, mid+1) == 1:
                ok = mid
            else:
                ng = mid
            mid = (ok+ng) // 2
        ans += N - ok
    print(ans)


if __name__ == '__main__':
    main()
0