結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2020-03-14 17:26:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,678 bytes |
| コンパイル時間 | 1,377 ms |
| コンパイル使用メモリ | 122,140 KB |
| 実行使用メモリ | 90,624 KB |
| 最終ジャッジ日時 | 2024-11-07 20:28:54 |
| 合計ジャッジ時間 | 27,847 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 TLE * 4 |
ソースコード
#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;
}
chocorusk