結果

問題 No.1036 Make One With GCD 2
ユーザー leaf_1415leaf_1415
提出日時 2021-04-16 05:14:23
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,000 bytes
コンパイル時間 2,350 ms
コンパイル使用メモリ 83,144 KB
実行使用メモリ 95,612 KB
最終ジャッジ日時 2023-09-15 07:25:17
合計ジャッジ時間 30,332 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 390 ms
90,884 KB
testcase_01 AC 369 ms
90,912 KB
testcase_02 AC 378 ms
90,968 KB
testcase_03 AC 154 ms
88,532 KB
testcase_04 AC 229 ms
89,696 KB
testcase_05 AC 67 ms
87,084 KB
testcase_06 AC 67 ms
87,096 KB
testcase_07 AC 184 ms
88,720 KB
testcase_08 AC 162 ms
88,464 KB
testcase_09 AC 494 ms
90,908 KB
testcase_10 AC 464 ms
90,580 KB
testcase_11 AC 505 ms
90,892 KB
testcase_12 AC 469 ms
90,584 KB
testcase_13 AC 646 ms
90,848 KB
testcase_14 AC 654 ms
90,848 KB
testcase_15 AC 615 ms
90,588 KB
testcase_16 AC 621 ms
90,576 KB
testcase_17 AC 637 ms
90,600 KB
testcase_18 AC 68 ms
87,004 KB
testcase_19 AC 68 ms
87,264 KB
testcase_20 AC 69 ms
87,268 KB
testcase_21 AC 69 ms
87,040 KB
testcase_22 AC 609 ms
90,640 KB
testcase_23 AC 462 ms
89,528 KB
testcase_24 AC 631 ms
90,684 KB
testcase_25 AC 581 ms
90,360 KB
testcase_26 AC 602 ms
90,636 KB
testcase_27 AC 67 ms
87,256 KB
testcase_28 AC 67 ms
87,320 KB
testcase_29 AC 67 ms
87,048 KB
testcase_30 AC 66 ms
87,156 KB
testcase_31 AC 67 ms
87,096 KB
testcase_32 AC 67 ms
87,132 KB
testcase_33 AC 67 ms
87,092 KB
testcase_34 AC 66 ms
87,092 KB
testcase_35 AC 67 ms
87,148 KB
testcase_36 AC 67 ms
87,160 KB
testcase_37 AC 67 ms
87,036 KB
testcase_38 AC 372 ms
90,956 KB
testcase_39 AC 415 ms
90,960 KB
testcase_40 AC 462 ms
89,528 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint gcd(llint a, llint b)
{
	if(b == 0) return a;
	return gcd(b, a%b);
}

struct SparseTable{
	typedef llint T;
	
	int size;
	vector<vector<T> > vec;
	vector<int> msb;
	
	T Ident(){return 0;}  //単位元
	T ope(T a, T b){return gcd(a, b);} //作用素
	
	SparseTable(){}
	SparseTable(int size){
		this->size = size;
		vec.resize(size+1);
		for(int i = 0; i <= size; i++) vec[i].resize(1<<size);
		for(int i = 0; i < (1<<size); i++) vec[0][i] = Ident();
		msb.resize((1<<size));
		for(int i = 2; i < (1<<size); i++) msb[i] = msb[i>>1]+1;
	}
	void set(int i, T val){
		vec[0][i] = val;
	}
	void calc(){
		for(int i = 1; i <= size; i++){
			for(int j = 0; j < (1<<size); j++){
				if(j+(1<<(i-1)) < (1<<size)){
					vec[i][j] = ope(vec[i-1][j], vec[i-1][j+(1<<(i-1))]);
				}
			}
		}
	}
	T query(int l, int r)
	{
		if(l > r) return Ident();
		int k = msb[r-l+1];
		return ope(vec[k][l], vec[k][r-(1<<k)+1]);
	}
};


llint n;
llint a[500005];
SparseTable sp(19);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) sp.set(i, a[i]);
	sp.calc();
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		llint ub = n+1, lb = i-1, mid;
		while(ub-lb>1){
			mid = (ub+lb)/2;
			if(mid >= i && sp.query(i, mid) == 1) ub = mid;
			else lb = mid;
		}
		ans += n-ub+1;
	}
	cout << ans << endl;
	
	return 0;
}
0