結果

問題 No.1036 Make One With GCD 2
ユーザー risujirohrisujiroh
提出日時 2020-04-24 21:30:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,262 bytes
コンパイル時間 2,421 ms
コンパイル使用メモリ 205,468 KB
実行使用メモリ 77,172 KB
最終ジャッジ日時 2023-10-14 19:12:22
合計ジャッジ時間 11,789 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 235 ms
77,108 KB
testcase_01 AC 186 ms
76,992 KB
testcase_02 AC 171 ms
77,024 KB
testcase_03 AC 42 ms
28,656 KB
testcase_04 AC 71 ms
49,644 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 80 ms
32,688 KB
testcase_08 AC 65 ms
26,716 KB
testcase_09 AC 201 ms
75,224 KB
testcase_10 AC 186 ms
69,936 KB
testcase_11 AC 203 ms
76,920 KB
testcase_12 AC 190 ms
70,480 KB
testcase_13 AC 283 ms
73,308 KB
testcase_14 AC 282 ms
74,264 KB
testcase_15 AC 265 ms
69,620 KB
testcase_16 AC 269 ms
70,076 KB
testcase_17 AC 276 ms
72,140 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 263 ms
68,504 KB
testcase_23 AC 196 ms
50,068 KB
testcase_24 AC 274 ms
71,448 KB
testcase_25 AC 252 ms
64,832 KB
testcase_26 AC 262 ms
67,440 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,356 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,352 KB
testcase_38 AC 168 ms
77,080 KB
testcase_39 AC 255 ms
76,844 KB
testcase_40 AC 199 ms
49,936 KB
testcase_41 AC 246 ms
77,112 KB
testcase_42 AC 245 ms
76,976 KB
testcase_43 AC 235 ms
76,992 KB
testcase_44 AC 239 ms
77,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int ctz(int a) { return __builtin_ctz(a); }
int ctz(long long a) { return __builtin_ctzll(a); }
template <class T> T gcd(T a, T b) {
  a = abs(a), b = abs(b);
  if (a == 0) return b;
  int k = ctz(a | b);
  a >>= ctz(a);
  while (b) {
    b >>= ctz(b);
    if (a > b) swap(a, b);
    b -= a;
  }
  return a << k;
}

template <class T> struct sparse_table {
  vector<vector<T>> t;
  sparse_table(const vector<T>& v = {}) : t{v} {
    for (int k = 1, n = v.size(); 1 << k <= n; ++k) {
      t.emplace_back(n - (1 << k) + 1);
      for (int i = 0; i + (1 << k) <= n; ++i)
        t[k][i] = gcd(t[k - 1][i], t[k - 1][i + (1 << (k - 1))]);
    }
  }
  T fold(int l, int r) const {
    assert(l < r);
    int k = __lg(r - l);
    return gcd(t[k][l], t[k][r - (1 << k)]);
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  sparse_table st(a);
  auto res = (long long)n * (n + 1) / 2;
  for (int l = 0, r = 0; l < n; ++l) {
    while (r <= l or (r <= n and st.fold(l, r) > 1)) {
      ++r;
    }
    res -= r - l - 1;
  }
  cout << res << '\n';
}
0