結果

問題 No.1036 Make One With GCD 2
ユーザー iqueue02iqueue02
提出日時 2020-04-25 11:28:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,543 ms / 2,000 ms
コード長 1,336 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 171,500 KB
実行使用メモリ 11,540 KB
最終ジャッジ日時 2023-10-14 19:47:04
合計ジャッジ時間 26,300 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 932 ms
11,308 KB
testcase_01 AC 531 ms
11,244 KB
testcase_02 AC 518 ms
11,280 KB
testcase_03 AC 96 ms
7,296 KB
testcase_04 AC 179 ms
11,280 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 183 ms
7,156 KB
testcase_08 AC 150 ms
7,272 KB
testcase_09 AC 635 ms
11,292 KB
testcase_10 AC 577 ms
11,292 KB
testcase_11 AC 640 ms
11,304 KB
testcase_12 AC 595 ms
11,292 KB
testcase_13 AC 835 ms
11,392 KB
testcase_14 AC 865 ms
11,284 KB
testcase_15 AC 801 ms
11,540 KB
testcase_16 AC 774 ms
11,232 KB
testcase_17 AC 807 ms
11,240 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 3 ms
4,356 KB
testcase_20 AC 4 ms
4,352 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 765 ms
11,292 KB
testcase_23 AC 557 ms
11,240 KB
testcase_24 AC 801 ms
11,276 KB
testcase_25 AC 743 ms
11,344 KB
testcase_26 AC 756 ms
11,280 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 716 ms
11,284 KB
testcase_39 AC 1,543 ms
11,244 KB
testcase_40 AC 559 ms
11,272 KB
testcase_41 AC 1,211 ms
11,244 KB
testcase_42 AC 1,239 ms
11,224 KB
testcase_43 AC 1,154 ms
11,280 KB
testcase_44 AC 1,229 ms
11,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;


ll gcd(ll a, ll b){
  if(b == 0) return a;
  return gcd(b,a%b);
}

template <typename T> 
struct SegmentTree {
  
  int n;
  vector<T> node;

  T f(T a, T b) {return gcd(a, b);}

  SegmentTree (int sz, T init = 0) {
    n = 1; while (n < sz) n <<= 1;
    node.assign(2*n, init);
    for (int i = n - 2; i >= 0; i--) node[i] = f(node[2*i+1], node[2*i+2]);
  }

  void update(int k, T x) {
    k += (n - 1);
    node[k] = x;
    while (k > 0) {
      k = (k - 1) >> 1;
      node[k] = f(node[2*k+1], node[2*k+2]);
    } 
  }

  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2*k+1, l, (l+r)/2);
    T vr = query(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }

  T getvalue(int k) {
    return query(k,k+1);
  }
};

int main(){
  int n;
  cin >> n;
  SegmentTree<ll> seg(n);
  rep(i,n) {
    ll a;
    cin >> a;
    seg.update(i, a);
  }

  ll res = 0;
  int r = 0;
  for (int l = 0; l < n; l++) {
    if (l > r) r = l;
    while (r < n && seg.query(l, r + 1) > 1) r++;
    res += n - r;
  }
  cout << res << endl;
  return 0; 
}   
0