結果

問題 No.1036 Make One With GCD 2
ユーザー optopt
提出日時 2020-04-25 00:28:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 608 ms / 2,000 ms
コード長 3,121 bytes
コンパイル時間 2,933 ms
コンパイル使用メモリ 209,988 KB
実行使用メモリ 19,212 KB
最終ジャッジ日時 2023-10-14 19:36:34
合計ジャッジ時間 16,905 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 496 ms
19,128 KB
testcase_01 AC 346 ms
18,996 KB
testcase_02 AC 326 ms
19,212 KB
testcase_03 AC 70 ms
10,156 KB
testcase_04 AC 124 ms
16,252 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,356 KB
testcase_07 AC 115 ms
10,364 KB
testcase_08 AC 95 ms
9,832 KB
testcase_09 AC 378 ms
18,740 KB
testcase_10 AC 351 ms
18,392 KB
testcase_11 AC 388 ms
18,992 KB
testcase_12 AC 356 ms
18,488 KB
testcase_13 AC 473 ms
18,668 KB
testcase_14 AC 477 ms
18,956 KB
testcase_15 AC 445 ms
18,336 KB
testcase_16 AC 449 ms
18,488 KB
testcase_17 AC 461 ms
18,600 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 3 ms
4,348 KB
testcase_22 AC 441 ms
18,484 KB
testcase_23 AC 324 ms
16,352 KB
testcase_24 AC 458 ms
18,676 KB
testcase_25 AC 417 ms
17,812 KB
testcase_26 AC 434 ms
18,068 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 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 1 ms
4,348 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 1 ms
4,356 KB
testcase_38 AC 411 ms
19,100 KB
testcase_39 AC 473 ms
19,080 KB
testcase_40 AC 326 ms
16,188 KB
testcase_41 AC 599 ms
19,160 KB
testcase_42 AC 589 ms
19,128 KB
testcase_43 AC 568 ms
19,068 KB
testcase_44 AC 608 ms
19,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


template<typename T>
struct SegmentTree {
  int m, n; // m: size of original vector, n: size of segment tree
  vector<T> d;
  T idt = 0;
  T op(T &a, T &b) {
    // return a + b;
    return gcd(a, b);
  }

  SegmentTree(vector<T> v) : m(v.size()) {
    n = 1; while(n < m) n <<= 1;
    d.assign(2*n-1, 0);
    rep(i, m) d[i+n-1] = v[i];
    drep(i, n-1) d[i] = op(d[i*2+1], d[i*2+2]);
  }
 
  void add(int k, T val) {
    k += n-1, d[k] += val;
    while (k) k = (k-1)/2, d[k] = op(d[2*k+1], d[2*k+2]);
  } 

  void set(int k, T val) {
    k += n-1, d[k] = val;
    while (k) k = (k-1)/2, d[k] = op(d[2*k+1], d[2*k+2]);
  }
 
  T op_range(int a, int b, int k=0, int l=0, int r=-1) {
    if (r < 0) r = n;
    if (b <= l || r <= a) return idt;
    if (a <= l && r <= b) return d[k];
    T vl = op_range(a, b, 2*k+1, l, (l+r)/2);
    T vr = op_range(a, b, 2*k+2, (l+r)/2, r);
    return op(vl, vr);
  }
 
  T get(int a) { return d[n-1+a]; }
 
  vector<T> get_all() {
    vector<T> res(m);
    copy(d.begin()+n-1, d.begin()+n+m-1, res.begin());
    return res;
  }
};


int main() {
  ll n; cin >> n;
  Vll a(n); cin >> a;

  ll ans = 0;
  SegmentTree<ll> st(a);

  int j = 0;
  rep(i, n) {
    ll y = st.op_range(i, j+1);
    while (j < n && st.op_range(i, j+1) > 1) ++j;
    ans += n-j;
    if (i == j) ++j;
  }

  cout << ans << endl;
  return 0;
}
0