結果

問題 No.1036 Make One With GCD 2
ユーザー beetbeet
提出日時 2020-04-24 21:53:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,210 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 2,856 ms
コンパイル使用メモリ 218,160 KB
実行使用メモリ 114,164 KB
最終ジャッジ日時 2023-08-07 16:19:58
合計ジャッジ時間 28,663 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 592 ms
85,052 KB
testcase_01 AC 397 ms
85,232 KB
testcase_02 AC 202 ms
85,160 KB
testcase_03 AC 58 ms
31,876 KB
testcase_04 AC 99 ms
56,272 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 240 ms
42,176 KB
testcase_08 AC 183 ms
35,152 KB
testcase_09 AC 1,111 ms
112,104 KB
testcase_10 AC 1,065 ms
104,404 KB
testcase_11 AC 1,162 ms
114,164 KB
testcase_12 AC 1,072 ms
105,208 KB
testcase_13 AC 1,157 ms
109,392 KB
testcase_14 AC 1,166 ms
110,408 KB
testcase_15 AC 1,078 ms
103,552 KB
testcase_16 AC 1,099 ms
104,392 KB
testcase_17 AC 1,210 ms
107,724 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 4 ms
4,384 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 1,062 ms
102,416 KB
testcase_23 AC 781 ms
76,080 KB
testcase_24 AC 1,115 ms
106,560 KB
testcase_25 AC 1,010 ms
97,220 KB
testcase_26 AC 1,069 ms
100,752 KB
testcase_27 AC 2 ms
4,508 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 201 ms
85,416 KB
testcase_39 AC 585 ms
85,112 KB
testcase_40 AC 797 ms
76,064 KB
testcase_41 AC 840 ms
85,192 KB
testcase_42 AC 828 ms
85,172 KB
testcase_43 AC 816 ms
85,180 KB
testcase_44 AC 862 ms
85,180 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