結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | terasa |
提出日時 | 2022-05-28 18:27:18 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,686 bytes |
コンパイル時間 | 148 ms |
コンパイル使用メモリ | 82,256 KB |
実行使用メモリ | 230,116 KB |
最終ジャッジ日時 | 2024-09-20 23:25:37 |
合計ジャッジ時間 | 24,734 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 535 ms
191,992 KB |
testcase_02 | WA | - |
testcase_03 | AC | 77 ms
95,488 KB |
testcase_04 | AC | 108 ms
112,472 KB |
testcase_05 | AC | 45 ms
55,296 KB |
testcase_06 | AC | 43 ms
55,168 KB |
testcase_07 | AC | 219 ms
126,144 KB |
testcase_08 | AC | 194 ms
112,012 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 | 58 ms
65,792 KB |
testcase_19 | AC | 71 ms
72,832 KB |
testcase_20 | AC | 78 ms
76,928 KB |
testcase_21 | AC | 77 ms
77,056 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 42 ms
55,296 KB |
testcase_28 | AC | 42 ms
54,912 KB |
testcase_29 | WA | - |
testcase_30 | AC | 44 ms
55,424 KB |
testcase_31 | AC | 45 ms
55,552 KB |
testcase_32 | AC | 47 ms
56,320 KB |
testcase_33 | AC | 46 ms
55,424 KB |
testcase_34 | AC | 48 ms
56,192 KB |
testcase_35 | WA | - |
testcase_36 | AC | 44 ms
55,296 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
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: r += 1 if r > len(b): d = len(b) - l - 1 ans -= d * (d - 1) // 2 return d = r - l - 1 ans -= d * (d - 1) // 2 while st.query(l, r) == 1: l += 1 solve(b) print(ans)