結果

問題 No.1036 Make One With GCD 2
ユーザー Y17Y17
提出日時 2020-04-24 22:29:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,319 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 171,016 KB
実行使用メモリ 94,592 KB
最終ジャッジ日時 2024-04-25 10:11:58
合計ジャッジ時間 31,204 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 657 ms
94,592 KB
testcase_01 AC 550 ms
89,088 KB
testcase_02 AC 675 ms
89,088 KB
testcase_03 AC 146 ms
43,648 KB
testcase_04 AC 285 ms
87,808 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 227 ms
43,904 KB
testcase_08 AC 191 ms
43,648 KB
testcase_09 AC 667 ms
89,088 KB
testcase_10 AC 624 ms
88,704 KB
testcase_11 AC 679 ms
89,088 KB
testcase_12 AC 628 ms
88,960 KB
testcase_13 AC 924 ms
88,960 KB
testcase_14 AC 928 ms
89,088 KB
testcase_15 AC 878 ms
88,832 KB
testcase_16 AC 877 ms
88,704 KB
testcase_17 AC 903 ms
88,832 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 6 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 861 ms
88,704 KB
testcase_23 AC 651 ms
87,936 KB
testcase_24 AC 903 ms
88,832 KB
testcase_25 AC 825 ms
88,704 KB
testcase_26 AC 851 ms
88,576 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 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 659 ms
89,216 KB
testcase_39 AC 695 ms
89,088 KB
testcase_40 AC 653 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