結果

問題 No.1036 Make One With GCD 2
ユーザー autumn-eelautumn-eel
提出日時 2020-04-24 21:40:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,174 bytes
コンパイル時間 1,855 ms
コンパイル使用メモリ 171,140 KB
実行使用メモリ 100,608 KB
最終ジャッジ日時 2024-04-25 09:20:36
合計ジャッジ時間 28,572 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 422 ms
100,608 KB
testcase_01 AC 425 ms
95,232 KB
testcase_02 AC 422 ms
95,232 KB
testcase_03 AC 134 ms
37,120 KB
testcase_04 AC 245 ms
62,976 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 176 ms
42,368 KB
testcase_08 AC 139 ms
35,328 KB
testcase_09 AC 551 ms
93,056 KB
testcase_10 AC 524 ms
86,784 KB
testcase_11 AC 564 ms
94,848 KB
testcase_12 AC 533 ms
87,552 KB
testcase_13 AC 692 ms
90,880 KB
testcase_14 AC 706 ms
91,904 KB
testcase_15 AC 655 ms
86,272 KB
testcase_16 AC 660 ms
87,040 KB
testcase_17 AC 679 ms
89,600 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 662 ms
85,248 KB
testcase_23 AC 481 ms
63,488 KB
testcase_24 AC 672 ms
88,576 KB
testcase_25 AC 612 ms
81,024 KB
testcase_26 AC 650 ms
83,840 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 419 ms
95,232 KB
testcase_39 AC 454 ms
95,232 KB
testcase_40 AC 480 ms
63,488 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

template<class T>
class SparseTable {
	const int MAX_LOG=22;
	vector<vector<T>>t;
	vector<int>l2;
	function<T(T,T)>F;
public:
	int n;
	T INIT;
	void init(int n_,function<T(T,T)>f){
		n=n_;
		F=f;
		t=vector<vector<T>>(MAX_LOG);
		rep(i,MAX_LOG)t[i].assign(n,0);
		l2.assign(n+1,0);
		int k=0;
		rep(i,n+1){
			while((1<<(k+1))<=i)k++;
			l2[i]=k;
		}
	}
	void build(int n_,T*a,function<T(T,T)>f){
		init(n_,f);
		rep(i,n)t[0][i]=a[i];
		for (int i=1;i<MAX_LOG;i++) {
			for(int j=0;j+(1<<i)<=n;j++){
				t[i][j]=F(t[i-1][j],t[i-1][j+(1<<(i-1))]);
			}
		}
	}
	T query(int a,int b) {
		int l=l2[b-a];
		return F(t[l][a],t[l][b-(1<<l)]);
	}
};

ll a[600000];

int main(){
	int n;cin>>n;
	rep(i,n)scanf("%lld",&a[i]);
	SparseTable<ll>seg;
	seg.build(n,a,[](ll a,ll b){return __gcd(a,b);});
	ll ans=0;
	rep(i,n){
		int ok=n,ng=i-1;
		while(ok-ng>1){
			int t=(ok+ng)/2;
			if(seg.query(i,t+1)==1)ok=t;
			else ng=t;
		}
		ans+=(n-1)-ok+1;
	}
	cout<<ans<<endl;
}
0