結果

問題 No.1036 Make One With GCD 2
ユーザー 沙耶花沙耶花
提出日時 2020-04-25 19:57:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 489 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 2,242 ms
コンパイル使用メモリ 199,876 KB
実行使用メモリ 81,536 KB
最終ジャッジ日時 2024-04-25 07:44:37
合計ジャッジ時間 17,712 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 472 ms
81,408 KB
testcase_01 AC 319 ms
81,280 KB
testcase_02 AC 180 ms
81,408 KB
testcase_03 AC 96 ms
30,720 KB
testcase_04 AC 164 ms
54,144 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 131 ms
34,944 KB
testcase_08 AC 103 ms
29,184 KB
testcase_09 AC 342 ms
79,488 KB
testcase_10 AC 315 ms
74,368 KB
testcase_11 AC 347 ms
81,152 KB
testcase_12 AC 344 ms
75,008 KB
testcase_13 AC 411 ms
77,696 KB
testcase_14 AC 407 ms
78,592 KB
testcase_15 AC 389 ms
73,856 KB
testcase_16 AC 384 ms
74,496 KB
testcase_17 AC 404 ms
76,672 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 375 ms
72,960 KB
testcase_23 AC 273 ms
54,528 KB
testcase_24 AC 400 ms
75,776 KB
testcase_25 AC 361 ms
69,376 KB
testcase_26 AC 396 ms
71,808 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 1 ms
5,376 KB
testcase_38 AC 178 ms
81,408 KB
testcase_39 AC 469 ms
81,408 KB
testcase_40 AC 282 ms
54,528 KB
testcase_41 AC 475 ms
81,280 KB
testcase_42 AC 475 ms
81,408 KB
testcase_43 AC 461 ms
81,280 KB
testcase_44 AC 489 ms
81,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000001

template <typename T>
struct sparse_table{
	const T init_value = 0;
	
	vector<T> v;
	int n;
	int sz;
	sparse_table(vector<T> &x){
		sz = x.size();
		for(int i=0;true;i++){
			if((1<<i)>sz){
				n = i;
				break;
			}
		}
		v.resize(sz*n,init_value);
		
		for(int i=0;i<sz;i++){
			v[i] = x[i];
		}
		
		for(int i=1;i<n;i++){
			for(int j=0;j<sz+1-(1<<i);j++){
				int temp = j+(1<<(i-1));
				v[i*sz+j] = func(v[(i-1)*sz+j],v[(i-1)*sz+temp]);
			}
		}
	}
	
	T query(int l,int r){
		int x = 31-__builtin_clz(r-l);
		return func(v[sz*x+l],v[sz*x+r-(1<<x)]);
	}
	
	T func(T a,T b){
		return gcd(a,b);//min(a,b);
	}
};

int main(){
	
	long long N;
	cin>>N;
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		scanf("%lld",&A[i]);
	}
	
	sparse_table<long long> seg(A);
	
	long long ans = 0;
	
	for(int i=0;i<N;i++){
		if(seg.query(i,N)>1)break;
		int ok = i;
		int ng = N+1;
		
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			if(seg.query(i,mid)==1)ng = mid;
			else ok=mid;
		}
		
		ans += N+1-ng;
	}
	
	cout<<ans<<endl;
		
	return 0;
}
0