結果

問題 No.1036 Make One With GCD 2
ユーザー furafura
提出日時 2021-05-28 17:29:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 3,961 ms
コンパイル使用メモリ 206,820 KB
実行使用メモリ 79,148 KB
最終ジャッジ日時 2023-10-14 20:46:28
合計ジャッジ時間 12,486 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 236 ms
79,148 KB
testcase_01 AC 193 ms
79,084 KB
testcase_02 AC 171 ms
79,088 KB
testcase_03 AC 47 ms
29,092 KB
testcase_04 AC 79 ms
51,040 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 82 ms
33,316 KB
testcase_08 AC 64 ms
27,632 KB
testcase_09 AC 205 ms
77,300 KB
testcase_10 AC 190 ms
71,960 KB
testcase_11 AC 214 ms
78,828 KB
testcase_12 AC 193 ms
72,432 KB
testcase_13 AC 282 ms
75,456 KB
testcase_14 AC 284 ms
76,244 KB
testcase_15 AC 273 ms
71,500 KB
testcase_16 AC 270 ms
71,864 KB
testcase_17 AC 280 ms
74,132 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 3 ms
4,352 KB
testcase_20 AC 3 ms
4,352 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 AC 263 ms
70,228 KB
testcase_23 AC 200 ms
51,300 KB
testcase_24 AC 274 ms
73,404 KB
testcase_25 AC 253 ms
66,820 KB
testcase_26 AC 263 ms
69,524 KB
testcase_27 AC 1 ms
4,368 KB
testcase_28 AC 1 ms
4,372 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 1 ms
4,352 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 170 ms
79,060 KB
testcase_39 AC 256 ms
79,008 KB
testcase_40 AC 194 ms
51,388 KB
testcase_41 AC 238 ms
79,132 KB
testcase_42 AC 240 ms
79,080 KB
testcase_43 AC 236 ms
79,096 KB
testcase_44 AC 229 ms
79,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class B>
class sparse_table{
	vector<vector<B>> st;
	vector<int> h;
public:
	sparse_table()=default;
	template<class T>
	sparse_table(const vector<T>& a){ build(a); }

	template<class T>
	void build(const vector<T>& a){
		int n=a.size();
		h.assign(n+1,0);
		for(int i=2;i<=n;i++) h[i]=h[i>>1]+1;
		st.resize(h[n]+1);
		st[0].resize(n);
		rep(i,n) st[0][i]=a[i];
		for(int i=1;i<h[n]+1;i++){
			st[i].resize(n-(1<<i)+1);
			rep(j,n-(1<<i)+1) st[i][j]=st[i-1][j]*st[i-1][j+(1<<(i-1))];
		}
	}

	B product(int l,int r)const{
		int i=h[r-l];
		return st[i][l]*st[i][r-(1<<i)];
	}
};

template<class T>
class gcd_monoid{
	T a;
public:
	gcd_monoid(const T& val=T()):a(val){}
	gcd_monoid operator*(const gcd_monoid& x)const{
		return gcd(a,x.a);
	}
	T& get(){ return a; }
	const T& get()const{ return a; }
};

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	sparse_table<gcd_monoid<lint>> ST(a);

	lint ans=0;
	for(int l=0,r=0;l<n;l++){
		r=max(r,l+1);
		while(r<n && ST.product(l,r).get()>1) r++;
		if(r==n && ST.product(l,r).get()>1) continue;
		ans+=n-r+1;
	}
	printf("%lld\n",ans);

	return 0;
}
0