結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | terasa |
提出日時 | 2022-06-12 14:07:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 753 ms / 2,000 ms |
コード長 | 2,095 bytes |
コンパイル時間 | 204 ms |
コンパイル使用メモリ | 82,588 KB |
実行使用メモリ | 193,700 KB |
最終ジャッジ日時 | 2024-09-23 02:10:53 |
合計ジャッジ時間 | 21,677 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 668 ms
190,268 KB |
testcase_01 | AC | 366 ms
155,784 KB |
testcase_02 | AC | 572 ms
151,724 KB |
testcase_03 | AC | 139 ms
103,276 KB |
testcase_04 | AC | 195 ms
117,132 KB |
testcase_05 | AC | 45 ms
54,656 KB |
testcase_06 | AC | 45 ms
54,656 KB |
testcase_07 | AC | 225 ms
111,164 KB |
testcase_08 | AC | 187 ms
100,020 KB |
testcase_09 | AC | 476 ms
153,624 KB |
testcase_10 | AC | 447 ms
170,648 KB |
testcase_11 | AC | 492 ms
154,612 KB |
testcase_12 | AC | 471 ms
171,348 KB |
testcase_13 | AC | 629 ms
181,036 KB |
testcase_14 | AC | 630 ms
189,896 KB |
testcase_15 | AC | 579 ms
176,208 KB |
testcase_16 | AC | 603 ms
178,064 KB |
testcase_17 | AC | 619 ms
179,972 KB |
testcase_18 | AC | 64 ms
68,864 KB |
testcase_19 | AC | 67 ms
71,552 KB |
testcase_20 | AC | 76 ms
76,800 KB |
testcase_21 | AC | 77 ms
76,928 KB |
testcase_22 | AC | 585 ms
175,216 KB |
testcase_23 | AC | 446 ms
134,252 KB |
testcase_24 | AC | 608 ms
178,676 KB |
testcase_25 | AC | 564 ms
164,340 KB |
testcase_26 | AC | 585 ms
172,884 KB |
testcase_27 | AC | 44 ms
54,528 KB |
testcase_28 | AC | 44 ms
55,296 KB |
testcase_29 | AC | 44 ms
55,296 KB |
testcase_30 | AC | 45 ms
55,040 KB |
testcase_31 | AC | 46 ms
55,808 KB |
testcase_32 | AC | 47 ms
55,808 KB |
testcase_33 | AC | 44 ms
55,040 KB |
testcase_34 | AC | 47 ms
55,808 KB |
testcase_35 | AC | 46 ms
55,040 KB |
testcase_36 | AC | 47 ms
55,040 KB |
testcase_37 | AC | 47 ms
54,656 KB |
testcase_38 | AC | 753 ms
193,700 KB |
testcase_39 | AC | 576 ms
193,312 KB |
testcase_40 | AC | 457 ms
134,900 KB |
testcase_41 | AC | 684 ms
193,312 KB |
testcase_42 | AC | 673 ms
193,332 KB |
testcase_43 | AC | 748 ms
193,312 KB |
testcase_44 | AC | 742 ms
193,316 KB |
ソースコード
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)