結果

問題 No.1036 Make One With GCD 2
ユーザー leaf_1415leaf_1415
提出日時 2020-04-24 21:51:44
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,816 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 84,148 KB
実行使用メモリ 89,088 KB
最終ジャッジ日時 2024-04-25 09:58:15
合計ジャッジ時間 26,926 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 447 ms
88,960 KB
testcase_01 AC 383 ms
89,088 KB
testcase_02 AC 464 ms
88,960 KB
testcase_03 AC 165 ms
86,528 KB
testcase_04 AC 253 ms
87,680 KB
testcase_05 AC 74 ms
85,120 KB
testcase_06 AC 74 ms
85,120 KB
testcase_07 AC 197 ms
86,784 KB
testcase_08 AC 173 ms
86,528 KB
testcase_09 AC 509 ms
88,960 KB
testcase_10 AC 476 ms
88,704 KB
testcase_11 AC 508 ms
89,088 KB
testcase_12 AC 476 ms
88,704 KB
testcase_13 AC 646 ms
88,832 KB
testcase_14 AC 645 ms
88,832 KB
testcase_15 AC 617 ms
88,576 KB
testcase_16 AC 623 ms
88,704 KB
testcase_17 AC 628 ms
88,832 KB
testcase_18 AC 74 ms
85,248 KB
testcase_19 AC 74 ms
85,120 KB
testcase_20 AC 75 ms
85,120 KB
testcase_21 AC 78 ms
85,120 KB
testcase_22 AC 603 ms
88,704 KB
testcase_23 AC 473 ms
87,680 KB
testcase_24 AC 618 ms
88,704 KB
testcase_25 AC 571 ms
88,448 KB
testcase_26 AC 585 ms
88,576 KB
testcase_27 AC 80 ms
85,248 KB
testcase_28 AC 75 ms
85,248 KB
testcase_29 AC 76 ms
85,120 KB
testcase_30 AC 75 ms
85,248 KB
testcase_31 AC 75 ms
85,120 KB
testcase_32 AC 75 ms
85,248 KB
testcase_33 AC 76 ms
85,120 KB
testcase_34 AC 74 ms
85,120 KB
testcase_35 AC 74 ms
85,120 KB
testcase_36 AC 75 ms
85,120 KB
testcase_37 AC 74 ms
85,120 KB
testcase_38 AC 464 ms
89,088 KB
testcase_39 AC 442 ms
88,960 KB
testcase_40 AC 451 ms
87,680 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{
	int size;
	vector<vector<llint> > vec;
	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] = 0;  //
	}
	void set(int i, llint 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] = gcd(vec[i-1][j], vec[i-1][j+(1<<(i-1))]); //
				}
			}
		}
	}
	llint query(int l, int r)
	{
		int k = 0;
		for(int i = 0; r-l+1 >= (1<<i); i++) k = i;
		return gcd(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