結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | chocorusk |
提出日時 | 2020-04-26 04:24:47 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 851 ms / 2,000 ms |
コード長 | 2,587 bytes |
コンパイル時間 | 1,446 ms |
コンパイル使用メモリ | 134,164 KB |
実行使用メモリ | 19,344 KB |
最終ジャッジ日時 | 2023-10-14 20:18:19 |
合計ジャッジ時間 | 14,856 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 851 ms
19,156 KB |
testcase_01 | AC | 187 ms
19,144 KB |
testcase_02 | AC | 201 ms
19,172 KB |
testcase_03 | AC | 36 ms
10,188 KB |
testcase_04 | AC | 62 ms
16,384 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 1 ms
4,348 KB |
testcase_07 | AC | 70 ms
10,516 KB |
testcase_08 | AC | 58 ms
9,860 KB |
testcase_09 | AC | 247 ms
18,952 KB |
testcase_10 | AC | 229 ms
18,364 KB |
testcase_11 | AC | 251 ms
19,156 KB |
testcase_12 | AC | 233 ms
18,368 KB |
testcase_13 | AC | 363 ms
18,752 KB |
testcase_14 | AC | 365 ms
19,024 KB |
testcase_15 | AC | 343 ms
18,548 KB |
testcase_16 | AC | 349 ms
18,372 KB |
testcase_17 | AC | 357 ms
18,556 KB |
testcase_18 | AC | 2 ms
4,348 KB |
testcase_19 | AC | 2 ms
4,352 KB |
testcase_20 | AC | 3 ms
4,352 KB |
testcase_21 | AC | 3 ms
4,348 KB |
testcase_22 | AC | 339 ms
18,228 KB |
testcase_23 | AC | 252 ms
16,320 KB |
testcase_24 | AC | 353 ms
18,756 KB |
testcase_25 | AC | 324 ms
17,768 KB |
testcase_26 | AC | 333 ms
18,036 KB |
testcase_27 | AC | 2 ms
4,352 KB |
testcase_28 | AC | 2 ms
4,352 KB |
testcase_29 | AC | 2 ms
4,352 KB |
testcase_30 | AC | 1 ms
4,352 KB |
testcase_31 | AC | 2 ms
4,348 KB |
testcase_32 | AC | 2 ms
4,348 KB |
testcase_33 | AC | 1 ms
4,348 KB |
testcase_34 | AC | 2 ms
4,348 KB |
testcase_35 | AC | 1 ms
4,352 KB |
testcase_36 | AC | 2 ms
4,348 KB |
testcase_37 | AC | 2 ms
4,352 KB |
testcase_38 | AC | 198 ms
19,344 KB |
testcase_39 | AC | 684 ms
19,172 KB |
testcase_40 | AC | 252 ms
16,384 KB |
testcase_41 | AC | 565 ms
19,212 KB |
testcase_42 | AC | 539 ms
19,080 KB |
testcase_43 | AC | 603 ms
19,088 KB |
testcase_44 | AC | 637 ms
19,168 KB |
ソースコード
#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; } template<typename C> int binarysearch(int st, C &check, Monoid &s, int k, int l, int r){ if(k>=sz){ s=f(s, seg[k]); if(check(s)) return k-sz; else return -1; } int m=(l+r)>>1; if(m<=st) return binarysearch(st, check, s, 2*k+1, m, r); if(st<=l && !check(f(s, seg[k]))){ s=f(s, seg[k]); return -1; } int vl=binarysearch(st, check, s, 2*k, l, m); if(vl!=-1) return vl; return binarysearch(st, check, s, 2*k+1, m, r); } template<typename C> int binarysearch(int st, C &check){ Monoid s=e; return binarysearch(st, check, s, 1, 0, sz); } Monoid operator[](const int &k) const{ return seg[k+sz]; } }; ll gcd(ll a, ll b){ if(a==0) return b; if(b==0) return a; if(a<0) a=-a; if(b<0) b=-b; const int s=__builtin_ctzll(a|b); a>>=__builtin_ctzll(a); while(b){ b>>=__builtin_ctzll(b); if(a>b) swap(a, b); b-=a; } return a<<s; } 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; for(int i=0; i<n; i++){ auto check=[](ll x){ return x==1;}; int r=seg.binarysearch(i, check); if(r!=-1) ans+=n-r; } printf("%lld\n", ans); return 0; }