結果

問題 No.1036 Make One With GCD 2
ユーザー beetbeet
提出日時 2020-04-24 21:53:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,132 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 2,854 ms
コンパイル使用メモリ 212,324 KB
実行使用メモリ 114,472 KB
最終ジャッジ日時 2024-04-25 10:01:06
合計ジャッジ時間 26,186 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 534 ms
85,504 KB
testcase_01 AC 380 ms
85,376 KB
testcase_02 AC 218 ms
85,248 KB
testcase_03 AC 67 ms
32,128 KB
testcase_04 AC 115 ms
56,704 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 213 ms
42,568 KB
testcase_08 AC 168 ms
35,252 KB
testcase_09 AC 1,062 ms
112,184 KB
testcase_10 AC 960 ms
104,648 KB
testcase_11 AC 1,091 ms
114,472 KB
testcase_12 AC 1,002 ms
105,540 KB
testcase_13 AC 1,098 ms
109,624 KB
testcase_14 AC 1,132 ms
110,888 KB
testcase_15 AC 1,052 ms
103,912 KB
testcase_16 AC 1,049 ms
104,852 KB
testcase_17 AC 1,128 ms
107,864 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 1,032 ms
102,776 KB
testcase_23 AC 728 ms
76,488 KB
testcase_24 AC 1,069 ms
106,808 KB
testcase_25 AC 974 ms
97,644 KB
testcase_26 AC 1,044 ms
100,936 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 211 ms
85,248 KB
testcase_39 AC 541 ms
85,376 KB
testcase_40 AC 712 ms
76,364 KB
testcase_41 AC 739 ms
85,248 KB
testcase_42 AC 730 ms
85,376 KB
testcase_43 AC 709 ms
85,376 KB
testcase_44 AC 744 ms
85,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
template<typename T>
struct SparseTable{
  using F = function<T(T, T)>;
  vector< vector<T> > dat;
  vector<int> ht;
  const F f;

  SparseTable(){}
  SparseTable(F f):f(f){}

  void build(const vector<T> &v){
    int n=v.size(),h=1;
    while((1<<h)<=n) h++;
    dat.assign(h,vector<T>(n));
    ht.assign(n+1,0);
    for(int j=2;j<=n;j++) ht[j]=ht[j>>1]+1;

    for(int j=0;j<n;j++) dat[0][j]=v[j];
    for(int i=1,p=1;i<h;i++,p<<=1)
      for(int j=0;j<n;j++)
        dat[i][j]=f(dat[i-1][j],dat[i-1][min(j+p,n-1)]);
  };

  T query(int a,int b){
    int l=b-a;
    return f(dat[ht[l]][a],dat[ht[l]][b-(1<<ht[l])]);
  }
};
//END CUT HERE
#ifndef call_from_test

signed ARC023_D(){
    using ll = long long;
  int n;
  scanf("%d",&n);
  vector<ll> a(n);
  for(int i=0;i<n;i++) scanf("%lld",&a[i]);

  auto f=[](ll a,ll b){return gcd(a,b);};
  SparseTable<ll> st(f);
  st.build(a);

  map<ll, ll> ans;
  for(int i=0;i<n;i++){
    int l=i;
    ll pre=a[i],lst=st.query(i,n);
    while(lst!=pre){
      int r=n,pl=l;
      while(l+1<r){
        int m=(l+r)>>1;
        if(st.query(i,m)!=pre) r=m;
        else l=m;
      }
      ans[pre]+=l-pl;
      pre=st.query(i,r);
    }
    ans[lst]+=n-l;
  }

  printf("%lld\n",ans[1]);
  return 0;
}

/*
  verified on 2019/11/11
  https://atcoder.jp/contests/arc023/tasks/arc023_4
*/

signed main(){
  ARC023_D();
  return 0;
}
#endif
0