結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2020-03-14 17:40:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 905 ms / 2,000 ms |
| コード長 | 1,650 bytes |
| コンパイル時間 | 1,244 ms |
| コンパイル使用メモリ | 123,204 KB |
| 実行使用メモリ | 85,376 KB |
| 最終ジャッジ日時 | 2024-09-16 13:10:09 |
| 合計ジャッジ時間 | 16,003 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
ソースコード
#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++){
r=max(r, i+1);
while(r<=n){
if(seg.query(i, r)==1) break;
r++;
}
ans+=n+1-r;
}
printf("%lld\n", ans);
return 0;
}
chocorusk