結果

問題 No.1036 Make One With GCD 2
ユーザー terasaterasa
提出日時 2022-06-12 14:07:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 736 ms / 2,000 ms
コード長 2,095 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 81,404 KB
実行使用メモリ 193,040 KB
最終ジャッジ日時 2023-10-24 09:37:02
合計ジャッジ時間 23,653 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 730 ms
189,932 KB
testcase_01 AC 343 ms
154,840 KB
testcase_02 AC 561 ms
151,408 KB
testcase_03 AC 129 ms
102,948 KB
testcase_04 AC 186 ms
116,180 KB
testcase_05 AC 43 ms
55,832 KB
testcase_06 AC 43 ms
55,832 KB
testcase_07 AC 206 ms
110,604 KB
testcase_08 AC 181 ms
99,648 KB
testcase_09 AC 467 ms
153,744 KB
testcase_10 AC 441 ms
170,464 KB
testcase_11 AC 471 ms
154,140 KB
testcase_12 AC 456 ms
170,800 KB
testcase_13 AC 611 ms
180,444 KB
testcase_14 AC 611 ms
189,596 KB
testcase_15 AC 568 ms
175,560 KB
testcase_16 AC 585 ms
177,432 KB
testcase_17 AC 607 ms
179,660 KB
testcase_18 AC 63 ms
68,784 KB
testcase_19 AC 65 ms
72,920 KB
testcase_20 AC 75 ms
76,428 KB
testcase_21 AC 75 ms
76,420 KB
testcase_22 AC 576 ms
175,108 KB
testcase_23 AC 443 ms
135,512 KB
testcase_24 AC 589 ms
178,172 KB
testcase_25 AC 543 ms
163,772 KB
testcase_26 AC 570 ms
172,600 KB
testcase_27 AC 44 ms
55,832 KB
testcase_28 AC 43 ms
55,832 KB
testcase_29 AC 44 ms
55,832 KB
testcase_30 AC 44 ms
55,832 KB
testcase_31 AC 45 ms
55,832 KB
testcase_32 AC 46 ms
57,880 KB
testcase_33 AC 44 ms
55,832 KB
testcase_34 AC 45 ms
55,832 KB
testcase_35 AC 44 ms
55,832 KB
testcase_36 AC 44 ms
55,832 KB
testcase_37 AC 45 ms
55,832 KB
testcase_38 AC 736 ms
192,964 KB
testcase_39 AC 562 ms
193,020 KB
testcase_40 AC 442 ms
136,048 KB
testcase_41 AC 676 ms
193,036 KB
testcase_42 AC 667 ms
193,020 KB
testcase_43 AC 725 ms
193,024 KB
testcase_44 AC 731 ms
193,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


class SegTree:
    def __init__(self, N, func, e):
        self.N = N
        self.func = func
        self.X = [e] * (N << 1)
        self.e = e

    def build(self, seq):
        for i in range(self.N):
            self.X[self.N + i] = seq[i]
        for i in range(self.N)[::-1]:
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def add(self, i, x):
        i += self.N
        self.X[i] += x
        while i > 1:
            i >>= 1
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def update(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def query(self, L, R):
        L += self.N
        R += self.N
        vL = self.e
        vR = self.e
        while L < R:
            if L & 1:
                vL = self.func(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.func(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.func(vL, vR)


N = int(input())
A = list(map(int, input().split()))
st = SegTree(N, math.gcd, 0)
st.build(A)

ans = 0
l = 0
r = 1
ans = (1 + N) * N // 2
while r <= N:
    while st.query(l, r) == 1:
        l += 1
    ans -= r - l
    r += 1
print(ans)
0