結果

問題 No.1036 Make One With GCD 2
ユーザー MtSakaMtSaka
提出日時 2021-08-04 21:28:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 870 ms / 2,000 ms
コード長 3,539 bytes
コンパイル時間 4,873 ms
コンパイル使用メモリ 200,952 KB
実行使用メモリ 15,696 KB
最終ジャッジ日時 2023-10-14 21:25:18
合計ジャッジ時間 17,381 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 453 ms
15,580 KB
testcase_01 AC 100 ms
15,488 KB
testcase_02 AC 195 ms
15,476 KB
testcase_03 AC 21 ms
8,896 KB
testcase_04 AC 34 ms
14,088 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 39 ms
9,148 KB
testcase_08 AC 33 ms
8,772 KB
testcase_09 AC 227 ms
15,492 KB
testcase_10 AC 211 ms
15,064 KB
testcase_11 AC 232 ms
15,696 KB
testcase_12 AC 213 ms
15,168 KB
testcase_13 AC 374 ms
15,244 KB
testcase_14 AC 379 ms
15,320 KB
testcase_15 AC 353 ms
15,092 KB
testcase_16 AC 356 ms
15,124 KB
testcase_17 AC 367 ms
15,188 KB
testcase_18 AC 2 ms
4,368 KB
testcase_19 AC 2 ms
4,368 KB
testcase_20 AC 3 ms
4,372 KB
testcase_21 AC 2 ms
4,368 KB
testcase_22 AC 354 ms
15,000 KB
testcase_23 AC 258 ms
14,140 KB
testcase_24 AC 364 ms
15,148 KB
testcase_25 AC 333 ms
14,928 KB
testcase_26 AC 344 ms
14,972 KB
testcase_27 AC 2 ms
4,368 KB
testcase_28 AC 1 ms
4,368 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 2 ms
4,368 KB
testcase_31 AC 2 ms
4,368 KB
testcase_32 AC 2 ms
4,368 KB
testcase_33 AC 1 ms
4,372 KB
testcase_34 AC 1 ms
4,372 KB
testcase_35 AC 2 ms
4,368 KB
testcase_36 AC 2 ms
4,372 KB
testcase_37 AC 2 ms
4,372 KB
testcase_38 AC 375 ms
15,412 KB
testcase_39 AC 870 ms
15,464 KB
testcase_40 AC 259 ms
14,248 KB
testcase_41 AC 640 ms
15,684 KB
testcase_42 AC 630 ms
15,640 KB
testcase_43 AC 607 ms
15,488 KB
testcase_44 AC 655 ms
15,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//GIVE ME AC!!!!!!!!!!!!!!!!!
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define floatset() fixed<<setprecision(15)
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define rep(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define pb push_back
#define eb emplace_back
#define max_(a) *max_element(all(a))
#define min_(a) *min_element(all(a))
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using vl=vector<ll>;
using vi=vector<int>;
using vs=vector<string>;
using vc=vector<char>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vvc=vector<vc>;
using vd=vector<double>;
using vp=vector<P>;
using vb=vector<bool>;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const ll inf=2e18;
const ll MOD=1000000007;
const ll mod=998244353;
const double pi=acos(-1);
template<typename T1,typename T2 >
ostream &operator<<(ostream&os,const pair<T1,T2>&p) {
  os<<p.first<<" "<<p.second;
  return os;
}
template<typename T1,typename T2>
istream &operator>>(istream&is,pair<T1,T2>&p) {
  is>>p.first>>p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v) {
  for(int i=0;i<(int)v.size();i++) {
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  return os;
}
template<typename T>
istream &operator>>(istream&is,vector<T>&v) {
  for(T &in:v)is>>in;
  return is;
}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail) {
  cin>>head;
  scan(tail...);
}
template<class T>
void print(const T &t) { cout << t << '\n'; }
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail) {
  cout << head << ' ';
  print(tail...);
}
template<class... T>
void fin(const T &... a) {
  print(a...);
  exit(0);
}
template<typename T>
ll sum_(vector<T>&v){
  ll res=0;
  for(auto &e:v)res+=e;
  return res;
}
template<typename T1,typename T2>
inline bool chmax(T1&a,T2 b){return a<b&&(a=b,true);}
template<typename T1,typename T2>
inline bool chmin(T1&a,T2 b){return a>b&&(a=b,true);}
template<class S,S (*op)(S,S),S (*e)()>
struct segtree{
  private:
  int _n,size,idx=0;
  vector<S>seq;
  void update(int k){seq[k]=op(seq[2*k],seq[2*k+1]);}
  public:
  segtree():segtree(0){};
  segtree(int n):segtree(vector<S>(n,e())){}
  segtree(const vector<S>&v):_n(int(v.size())){
    while((1<<idx)<_n)idx++;
    size=1<<idx;
    seq=vector<S>(2*size,e());
    for(int i=0;i<_n;i++)seq[size+i]=v[i];
    for(int i=size-1;i>=1;i--)update(i);
  }
  void set(int p,S x){
    p+=size;
    seq[p]=x;
    for(int i=1;i<=idx;i++)update(p>>i);
  }
  S operator[](int p){return seq[p+size];}
  S query(int l,int r)const{
    S sml=e(),smr=e();
    l+=size,r+=size;
    while(l<r){
      if(l&1)sml=op(sml,seq[l++]);
      if(r&1)smr=op(seq[--r],smr);
      l>>=1,r>>=1;
    }
    return op(sml,smr);
  }
  S all_query()const{
    return seq[1];
  }
};
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll e(){return 0;}
int main(){
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  LL(n);
  vl a(n);
  scan(a);
  ll idx=0,ans=0;
  segtree<ll,gcd,e>s(a);
  rep(i,0,n){
    while(idx<n&&s.query(i,idx+1)!=1)idx++;
    ans+=n-idx;
  }
  fin(ans);
}
0