結果

問題 No.1036 Make One With GCD 2
ユーザー chocorusk
提出日時 2020-03-14 14:58:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 830 ms / 2,000 ms
コード長 2,057 bytes
コンパイル時間 1,084 ms
コンパイル使用メモリ 117,580 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-09-16 13:09:16
合計ジャッジ時間 14,017 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

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);
}
int main()
{
int n;
scanf("%d", &n);
vector<ll> a(n);
for(int i=0; i<n; i++){
scanf("%lld", &a[i]);
}
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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0