結果

問題 No.1036 Make One With GCD 2
ユーザー beetbeet
提出日時 2020-04-25 16:39:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 996 ms / 2,000 ms
コード長 2,531 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 209,756 KB
実行使用メモリ 85,224 KB
最終ジャッジ日時 2023-10-14 19:50:57
合計ジャッジ時間 21,297 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 268 ms
85,172 KB
testcase_01 AC 568 ms
85,128 KB
testcase_02 AC 186 ms
85,148 KB
testcase_03 AC 51 ms
31,776 KB
testcase_04 AC 88 ms
56,248 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 222 ms
36,348 KB
testcase_08 AC 175 ms
30,204 KB
testcase_09 AC 595 ms
83,432 KB
testcase_10 AC 538 ms
77,536 KB
testcase_11 AC 605 ms
84,896 KB
testcase_12 AC 583 ms
78,272 KB
testcase_13 AC 996 ms
81,324 KB
testcase_14 AC 958 ms
82,196 KB
testcase_15 AC 926 ms
77,312 KB
testcase_16 AC 930 ms
77,800 KB
testcase_17 AC 953 ms
80,256 KB
testcase_18 AC 2 ms
4,368 KB
testcase_19 AC 3 ms
4,368 KB
testcase_20 AC 4 ms
4,368 KB
testcase_21 AC 3 ms
4,368 KB
testcase_22 AC 895 ms
76,264 KB
testcase_23 AC 662 ms
56,880 KB
testcase_24 AC 957 ms
79,300 KB
testcase_25 AC 861 ms
72,328 KB
testcase_26 AC 902 ms
75,008 KB
testcase_27 AC 1 ms
4,372 KB
testcase_28 AC 2 ms
4,368 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 1 ms
4,368 KB
testcase_31 AC 2 ms
4,368 KB
testcase_32 AC 1 ms
4,368 KB
testcase_33 AC 2 ms
4,372 KB
testcase_34 AC 2 ms
4,368 KB
testcase_35 AC 1 ms
4,368 KB
testcase_36 AC 2 ms
4,368 KB
testcase_37 AC 2 ms
4,372 KB
testcase_38 AC 187 ms
85,224 KB
testcase_39 AC 449 ms
85,212 KB
testcase_40 AC 680 ms
56,792 KB
testcase_41 AC 382 ms
85,224 KB
testcase_42 AC 403 ms
85,112 KB
testcase_43 AC 259 ms
85,224 KB
testcase_44 AC 285 ms
85,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define PROBLEM "https://yukicoder.me/problems/4072"

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

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

  DisjointSparseTable(){}
  DisjointSparseTable(F f):f(f){}

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

    for(int j=0;j<n;j++) dat[0][j]=vs[j];
    for(int i=1;i<h;i++){
      int s=1<<i;
      for(int j=0;j<n;j+=s<<1){
        int t=min(j+s,n);
        dat[i][t-1]=vs[t-1];
        for(int k=t-2;k>=j;k--) dat[i][k]=f(vs[k],dat[i][k+1]);
        if(n<=t) break;
        dat[i][t]=vs[t];
        int r=min(t+s,n);
        for(int k=t+1;k<r;k++) dat[i][k]=f(dat[i][k-1],vs[k]);
      }
    }
  }

  T query(int l,int r){
    if(l>=--r) return dat[0][l];
    return f(dat[ht[l^r]][l],dat[ht[l^r]][r]);
  }

};
//END CUT HERE
#ifndef call_from_test

// find with non-idempotent monoid
signed CODECHEF_SEGPROD(){
  int T;
  scanf("%d",&T);

  int p;
  auto f=[&](int a,int b)->int{return (long long)a*b%p;};
  DisjointSparseTable<int> dst(f);

  for(int t=1;t<=T;t++){
    int n,q;
    scanf("%d %d %d",&n,&p,&q);
    vector<int> v(n);
    for(int i=0;i<n;i++) scanf("%d",&v[i]),v[i]%=p;
    vector<int> b(q/64+2);
    for(int i=0;i<(q/64+2);i++) scanf("%d",&b[i]);

    dst.build(v);

    int x=0,l=0,r=0;
    for(int i=0;i<q;i++){
      if(i%64==0){
        l=(b[i/64]+x)%n;
        r=(b[i/64+1]+x)%n;
      }else{
        l=(l+x)%n;
        r=(r+x)%n;
      }
      if(l>r) swap(l,r);
      x=dst.query(l,r+1)+1;
      if(x>=p) x-=p;
    }
    printf("%d\n",x);
  }
  return 0;
}
/*
  verified on 2019/10/29
  https://www.codechef.com/problems/SEGPROD
*/

//INSERT ABOVE HERE
signed main(){
  //CODECHEF_SEGPROD();
  return 0;
}
#endif

#undef call_from_test

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  using ll = long long;
  int n;
  cin>>n;
  vector<ll> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  auto f=[&](ll a,ll b){return gcd(a,b);};
  DisjointSparseTable<ll> dst(f);
  dst.build(as);

  ll ans=0;
  for(int l=0,r=0;l<n;l++){
    if(as[l]==1){
      ans+=n-l;
      continue;
    }
    if(r<=l) r=l+1;
    while(r<=n and dst.query(l,r)>1) r++;
    ans+=n-r+1;
  }

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