結果

問題 No.1036 Make One With GCD 2
ユーザー chocoruskchocorusk
提出日時 2020-03-14 15:25:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 829 ms / 2,000 ms
コード長 2,174 bytes
コンパイル時間 938 ms
コンパイル使用メモリ 115,144 KB
実行使用メモリ 19,192 KB
最終ジャッジ日時 2023-10-14 19:12:44
合計ジャッジ時間 13,633 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 454 ms
19,004 KB
testcase_01 AC 94 ms
19,192 KB
testcase_02 AC 180 ms
19,060 KB
testcase_03 AC 23 ms
10,064 KB
testcase_04 AC 39 ms
16,332 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 37 ms
10,500 KB
testcase_08 AC 30 ms
9,840 KB
testcase_09 AC 226 ms
18,828 KB
testcase_10 AC 208 ms
18,280 KB
testcase_11 AC 222 ms
19,104 KB
testcase_12 AC 211 ms
18,276 KB
testcase_13 AC 359 ms
18,848 KB
testcase_14 AC 366 ms
18,832 KB
testcase_15 AC 340 ms
18,324 KB
testcase_16 AC 352 ms
18,356 KB
testcase_17 AC 359 ms
18,672 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 347 ms
18,072 KB
testcase_23 AC 254 ms
16,316 KB
testcase_24 AC 358 ms
18,596 KB
testcase_25 AC 332 ms
17,840 KB
testcase_26 AC 341 ms
18,016 KB
testcase_27 AC 2 ms
4,356 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,352 KB
testcase_38 AC 408 ms
19,028 KB
testcase_39 AC 829 ms
19,004 KB
testcase_40 AC 248 ms
16,256 KB
testcase_41 AC 636 ms
19,076 KB
testcase_42 AC 644 ms
19,056 KB
testcase_43 AC 599 ms
19,024 KB
testcase_44 AC 654 ms
19,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<typename Monoid>
struct SegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	int sz;
	vector<Monoid> seg;
	const F f;
	const Monoid e;

	SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
	}

	SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
		for(int i=0; i<n; i++) seg[i+sz]=v[i];
		for(int i=sz-1; i>=1; i--){
			seg[i]=f(seg[2*i], seg[2*i+1]);
		}
	}

	void update(int k, const Monoid &x){
		k+=sz;
		seg[k]=x;
		while(k>1){
			k>>=1;
			seg[k]=f(seg[2*k], seg[2*k+1]);
		}
	}

	Monoid query(int a, int b){
		a+=sz, b+=sz;
		Monoid ret=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) ret=f(ret, seg[--b]);
			if(a&1) ret=f(ret, seg[a++]);
		}
		return ret;
	}

	/*Monoid query(int a, int b){ //演算が非可換のとき
		a+=sz, b+=sz;
		Monoid retl=e, retr=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) retr=f(seg[--b], retr);
			if(a&1) retl=f(retl, seg[a++]);
		}
		return f(retl, retr);
	}*/

	Monoid operator[](const int &k) const{
		return seg[k+sz];
	}
};
ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}
const ll MAXA=1000000000000000000;
const int MAXN=500000;
int main()
{
    int n;
	scanf("%d", &n);
	assert(1<=n && n<=MAXN);
	vector<ll> a(n);
	for(int i=0; i<n; i++){
		scanf("%lld", &a[i]);
		assert(1<=a[i] && a[i]<=MAXA);
	}
	SegmentTree<ll> seg(n, [&](ll x, ll y){ return gcd(x, y);}, 0, a);
	ll ans=0;
	int r=1;
	for(int i=0; i<n; i++){
		while(r<=n){
			if(seg.query(i, r)==1) break;
			r++;
		}
		ans+=n+1-r;
	}
	printf("%lld\n", ans);
	return 0;
}
0