結果

問題 No.1036 Make One With GCD 2
ユーザー chocoruskchocorusk
提出日時 2020-03-14 17:40:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,630 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 121,860 KB
実行使用メモリ 85,468 KB
最終ジャッジ日時 2024-04-24 17:17:04
合計ジャッジ時間 18,913 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 270 ms
85,468 KB
testcase_01 AC 256 ms
85,296 KB
testcase_02 AC 264 ms
85,280 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 375 ms
83,456 KB
testcase_10 AC 351 ms
77,888 KB
testcase_11 AC 386 ms
85,096 KB
testcase_12 AC 354 ms
78,588 KB
testcase_13 AC 514 ms
81,536 KB
testcase_14 AC 547 ms
82,432 KB
testcase_15 AC 486 ms
77,460 KB
testcase_16 AC 493 ms
77,824 KB
testcase_17 AC 508 ms
80,356 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 481 ms
76,452 KB
testcase_23 AC 345 ms
57,048 KB
testcase_24 AC 498 ms
79,488 KB
testcase_25 AC 456 ms
72,672 KB
testcase_26 AC 478 ms
75,240 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
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 RE -
testcase_39 AC 300 ms
85,280 KB
testcase_40 AC 348 ms
57,096 KB
testcase_41 AC 880 ms
85,376 KB
testcase_42 AC 878 ms
85,376 KB
testcase_43 AC 756 ms
85,272 KB
testcase_44 AC 821 ms
85,392 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 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++){
		while(r<=n){
			if(seg.query(i, r)==1) break;
			r++;
		}
		ans+=n+1-r;
	}
	printf("%lld\n", ans);
	return 0;
}
0