結果

問題 No.1036 Make One With GCD 2
ユーザー chocoruskchocorusk
提出日時 2020-03-14 17:26:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,678 bytes
コンパイル時間 1,413 ms
コンパイル使用メモリ 121,976 KB
実行使用メモリ 85,632 KB
最終ジャッジ日時 2024-04-25 09:53:48
合計ジャッジ時間 22,893 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 385 ms
85,376 KB
testcase_01 AC 399 ms
85,376 KB
testcase_02 AC 380 ms
85,248 KB
testcase_03 AC 118 ms
32,256 KB
testcase_04 AC 220 ms
56,704 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 159 ms
36,608 KB
testcase_08 AC 124 ms
30,464 KB
testcase_09 AC 517 ms
83,456 KB
testcase_10 AC 478 ms
77,824 KB
testcase_11 AC 513 ms
84,992 KB
testcase_12 AC 493 ms
78,464 KB
testcase_13 AC 635 ms
81,408 KB
testcase_14 AC 637 ms
82,432 KB
testcase_15 AC 599 ms
77,312 KB
testcase_16 AC 612 ms
77,824 KB
testcase_17 AC 629 ms
80,384 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 579 ms
76,544 KB
testcase_23 AC 429 ms
57,088 KB
testcase_24 AC 604 ms
79,360 KB
testcase_25 AC 541 ms
72,576 KB
testcase_26 AC 579 ms
75,264 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 382 ms
85,376 KB
testcase_39 AC 405 ms
85,376 KB
testcase_40 AC 427 ms
57,088 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
権限があれば一括ダウンロードができます

ソースコード

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 T>
struct SparseTable{
    vector<vector<T>> spt;
    vector<int> vlog;
	using F=function<T(T, T)>;
	const F f;
    SparseTable(const F f, const vector<T> &v):f(f){
        int b=0, n=v.size();
        while((1<<b)<=n) b++;
        spt.resize(b, vector<T>(n));
        for(int i=0; i<n; i++) spt[0][i]=v[i];
        for(int i=1; i<b; i++){
            for(int j=0; j+(1<<i)<=n; j++){
                spt[i][j]=f(spt[i-1][j], spt[i-1][j+(1<<(i-1))]);
            }
        }
        vlog.resize(n+1);
        for(int i=2; i<=n; i++) vlog[i]=vlog[i>>1]+1;
    }
    inline T query(int l, int r){
        int b=vlog[r-l];
        return f(spt[b][l], spt[b][r-(1<<b)]);
    }
};
ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}
int main()
{
    int n;
	scanf("%d", &n);
	vector<ll> a(n);
	for(int i=0; i<n; i++){
		scanf("%lld", &a[i]);
	}
	SparseTable<ll> seg([&](ll x, ll y){ return gcd(x, y);}, a);
	ll ans=0;
	int r=1;
	for(int i=0; i<n; i++){
		int l=i, r=n+1;
		while(r-l>1){
			int mid=(l+r)/2;
			if(seg.query(i, mid)==1) r=mid;
			else l=mid;
		}
		ans+=n+1-r;
	}
	printf("%lld\n", ans);
	return 0;
}
0