結果

問題 No.1036 Make One With GCD 2
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-04-24 22:39:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 501 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 206,612 KB
実行使用メモリ 89,104 KB
最終ジャッジ日時 2023-10-14 19:28:50
合計ジャッジ時間 16,337 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 449 ms
88,968 KB
testcase_01 AC 321 ms
88,952 KB
testcase_02 AC 406 ms
88,960 KB
testcase_03 AC 67 ms
43,468 KB
testcase_04 AC 114 ms
87,588 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 145 ms
43,648 KB
testcase_08 AC 123 ms
43,400 KB
testcase_09 AC 328 ms
88,784 KB
testcase_10 AC 310 ms
88,476 KB
testcase_11 AC 334 ms
88,988 KB
testcase_12 AC 311 ms
88,424 KB
testcase_13 AC 496 ms
88,940 KB
testcase_14 AC 501 ms
88,684 KB
testcase_15 AC 474 ms
88,348 KB
testcase_16 AC 475 ms
88,672 KB
testcase_17 AC 488 ms
88,612 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,356 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 AC 468 ms
88,460 KB
testcase_23 AC 358 ms
87,596 KB
testcase_24 AC 483 ms
88,600 KB
testcase_25 AC 444 ms
88,212 KB
testcase_26 AC 461 ms
88,396 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 2 ms
4,352 KB
testcase_38 AC 393 ms
89,068 KB
testcase_39 AC 485 ms
88,964 KB
testcase_40 AC 359 ms
87,416 KB
testcase_41 AC 461 ms
89,004 KB
testcase_42 AC 460 ms
88,920 KB
testcase_43 AC 452 ms
88,812 KB
testcase_44 AC 458 ms
89,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;


template< typename T >
struct SparseTable {
  vector< vector< T > > st;
  vector< ll > lookup;

  SparseTable(const vector< T > &v) {
    ll b = 0;
    while((1 << b) <= v.size()) ++b;
    st.assign(b, vector< T >(1 << b));
    for(ll i = 0; i < v.size(); i++) {
      st[0][i] = v[i];
    }
    for(ll i = 1; i < b; i++) {
      for(ll j = 0; j + (1 << i) <= (1 << b); j++) {
        st[i][j] = gcd(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
      }
    }
    lookup.resize(v.size() + 1);
    for(ll i = 2; i < (ll)lookup.size(); i++) {
      lookup[i] = lookup[i >> 1] + 1;
    }
  }

  inline T rmq(ll l, ll r) {
    ll b = lookup[r - l];
    return gcd(st[b][l], st[b][r - (1 << b)]);
  }
};

int main(){

    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,0,N) cin >> A[i];

    SparseTable<ll> spt(A);

    ll l = 0 , ans = N*(N-1)/2 + N;
    rep(r,0,N){
        if (A[r] == 1) continue;

        while (spt.rmq(l,r+1) == 1) l++;
        ans -= (r-l+1);

        //cout << l << " " << r << " " << spt.rmq(l,r+1) << endl;
    }

    cout << ans << endl;
}
0