結果

問題 No.1036 Make One With GCD 2
ユーザー Y17Y17
提出日時 2020-04-25 20:38:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,319 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 170,760 KB
実行使用メモリ 94,592 KB
最終ジャッジ日時 2024-04-25 08:49:24
合計ジャッジ時間 30,673 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 650 ms
94,592 KB
testcase_01 AC 552 ms
89,088 KB
testcase_02 AC 675 ms
89,216 KB
testcase_03 AC 147 ms
43,648 KB
testcase_04 AC 276 ms
87,808 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 223 ms
43,904 KB
testcase_08 AC 189 ms
43,520 KB
testcase_09 AC 668 ms
89,088 KB
testcase_10 AC 618 ms
88,704 KB
testcase_11 AC 672 ms
89,088 KB
testcase_12 AC 620 ms
88,960 KB
testcase_13 AC 921 ms
89,088 KB
testcase_14 AC 917 ms
89,088 KB
testcase_15 AC 866 ms
88,704 KB
testcase_16 AC 871 ms
88,704 KB
testcase_17 AC 899 ms
88,832 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 862 ms
88,832 KB
testcase_23 AC 652 ms
87,808 KB
testcase_24 AC 880 ms
88,832 KB
testcase_25 AC 812 ms
88,576 KB
testcase_26 AC 840 ms
88,704 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 649 ms
89,344 KB
testcase_39 AC 683 ms
89,088 KB
testcase_40 AC 651 ms
87,808 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  SparseTable(const vector< T > &v) {
    int b = 0;
    while((1 << b) <= v.size()) ++b;
    st.assign(b, vector< T >(1 << b));
    for(int i = 0; i < v.size(); i++) {
      st[0][i] = v[i];
    }
    for(int i = 1; i < b; i++) {
      for(int 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(int i = 2; i < lookup.size(); i++) {
      lookup[i] = lookup[i >> 1] + 1;
    }
  }

  inline T query(int l, int r) {
    int b = lookup[r - l];
    return __gcd(st[b][l], st[b][r - (1 << b)]);
  }
};

signed main(){
	int n;
	cin >> n;
	vector<int> a(n);

	for(int i = 0;i < n;i++){
		cin >> a[i];
	}

	SparseTable<int> seg(a);

	int ans = 0;
	for(int i = 0;i < n;i++){
		int l = i, r = n+1;
		while(r-l > 1){
			int mid = (l+r)/2;
			if(seg.query(i, mid) == 1){
				r = mid;
			}else{
				l = mid;
			}
		}
		ans += n-r+1;
	}

	cout << ans << endl;

	return 0;
}
0