結果

問題 No.1036 Make One With GCD 2
ユーザー NewGardenNewGarden
提出日時 2020-04-25 14:26:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,225 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 172,000 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-24 19:24:20
合計ジャッジ時間 22,442 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 73 ms
7,424 KB
testcase_04 AC 126 ms
11,392 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
5,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

ll gcd(ll a, ll b){ return b ? gcd(b,a%b):a; }

struct SegmentTree{
private:
  int n;
  vector<ll> node;
public:
  SegmentTree(int sz,ll init=0){
    n=1;
    while(n<sz)n*=2;
    node.resize(2*n-1,init);
  }
  void update(int k,ll x){
    k+=n-1;
    node[k]=x;
    while(k>0){
      k=(k-1)/2;
      node[k]=max(node[2*k+1],node[2*k+2]);
    }
  }

  //[a,b)でのmaxを返す
  ll get(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];
    ll xl=get(a,b,2*k+1,l,(l+r)/2);
    ll xr=get(a,b,2*k+2,(l+r)/2,r);
    return gcd(xl,xr);
  }   
};

int main(){
  int n;
  cin >> n;
  SegmentTree sg(n+1);
  rep(i,n){
    ll a; 
    cin >> a; 
    sg.update(i,a);
  }

  ll ans = 0;
  for(int i=0,r=1; i<n; i++){
    if(i==r){ r++; }
    while(r<n && sg.get(i,r)!=1){ r++; }
    ans += n-r+1;
  }
  cout << ans << endl;
  return 0;
}
0