結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | terasa |
提出日時 | 2022-05-28 18:39:39 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,678 bytes |
コンパイル時間 | 214 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 230,296 KB |
最終ジャッジ日時 | 2024-09-20 23:27:59 |
合計ジャッジ時間 | 24,447 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 671 ms
227,088 KB |
testcase_01 | AC | 551 ms
191,900 KB |
testcase_02 | AC | 584 ms
186,036 KB |
testcase_03 | AC | 75 ms
95,712 KB |
testcase_04 | AC | 106 ms
112,412 KB |
testcase_05 | AC | 43 ms
55,060 KB |
testcase_06 | AC | 44 ms
56,512 KB |
testcase_07 | AC | 221 ms
125,884 KB |
testcase_08 | AC | 192 ms
111,884 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 57 ms
66,340 KB |
testcase_19 | AC | 71 ms
73,808 KB |
testcase_20 | AC | 76 ms
77,364 KB |
testcase_21 | AC | 76 ms
77,032 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 44 ms
55,620 KB |
testcase_28 | AC | 49 ms
55,580 KB |
testcase_29 | AC | 47 ms
55,984 KB |
testcase_30 | AC | 43 ms
55,924 KB |
testcase_31 | AC | 45 ms
56,564 KB |
testcase_32 | AC | 45 ms
56,996 KB |
testcase_33 | AC | 44 ms
57,036 KB |
testcase_34 | AC | 45 ms
56,652 KB |
testcase_35 | AC | 43 ms
55,056 KB |
testcase_36 | AC | 43 ms
55,336 KB |
testcase_37 | AC | 43 ms
55,060 KB |
testcase_38 | AC | 793 ms
229,828 KB |
testcase_39 | AC | 584 ms
230,132 KB |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
ソースコード
import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict, Counter 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.X[L] vR = self.X[R - 1] 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())) B = [] tmp = [] cnt1 = 0 for a in A: if a == 1: cnt1 += 1 if len(tmp) > 0: B.append(tmp) tmp = [] else: tmp.append(a) if len(tmp) > 0: B.append(tmp) ans = (1 + N) * N // 2 - (N - cnt1) for b in B: st = SegTree(len(b), math.gcd, 1) st.build(b) def solve(b): global ans l = 0 r = 1 while r <= len(b): while st.query(l, r) > 1: if r == len(b): d = r - l ans -= d * (d - 1) // 2 return r += 1 d = r - l - 1 ans -= d * (d - 1) // 2 while st.query(l, r) == 1: l += 1 solve(b) print(ans)