結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | raven7959 |
提出日時 | 2022-05-10 11:49:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 769 ms / 2,000 ms |
コード長 | 5,900 bytes |
コンパイル時間 | 4,231 ms |
コンパイル使用メモリ | 201,804 KB |
実行使用メモリ | 15,360 KB |
最終ジャッジ日時 | 2023-09-24 16:30:51 |
合計ジャッジ時間 | 19,130 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 769 ms
15,120 KB |
testcase_01 | AC | 122 ms
15,176 KB |
testcase_02 | AC | 155 ms
15,064 KB |
testcase_03 | AC | 18 ms
8,576 KB |
testcase_04 | AC | 29 ms
13,608 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 41 ms
8,776 KB |
testcase_08 | AC | 34 ms
8,572 KB |
testcase_09 | AC | 163 ms
15,208 KB |
testcase_10 | AC | 153 ms
14,780 KB |
testcase_11 | AC | 169 ms
15,188 KB |
testcase_12 | AC | 154 ms
15,036 KB |
testcase_13 | AC | 265 ms
14,856 KB |
testcase_14 | AC | 265 ms
14,780 KB |
testcase_15 | AC | 251 ms
14,924 KB |
testcase_16 | AC | 253 ms
14,972 KB |
testcase_17 | AC | 260 ms
14,816 KB |
testcase_18 | AC | 2 ms
4,380 KB |
testcase_19 | AC | 2 ms
4,380 KB |
testcase_20 | AC | 2 ms
4,376 KB |
testcase_21 | AC | 2 ms
4,376 KB |
testcase_22 | AC | 248 ms
14,516 KB |
testcase_23 | AC | 185 ms
13,880 KB |
testcase_24 | AC | 257 ms
14,944 KB |
testcase_25 | AC | 237 ms
14,340 KB |
testcase_26 | AC | 245 ms
14,532 KB |
testcase_27 | AC | 2 ms
4,380 KB |
testcase_28 | AC | 1 ms
4,380 KB |
testcase_29 | AC | 1 ms
4,380 KB |
testcase_30 | AC | 2 ms
4,376 KB |
testcase_31 | AC | 2 ms
4,376 KB |
testcase_32 | AC | 2 ms
4,376 KB |
testcase_33 | AC | 1 ms
4,376 KB |
testcase_34 | AC | 1 ms
4,384 KB |
testcase_35 | AC | 1 ms
4,376 KB |
testcase_36 | AC | 2 ms
4,376 KB |
testcase_37 | AC | 2 ms
4,376 KB |
testcase_38 | AC | 151 ms
15,172 KB |
testcase_39 | AC | 625 ms
15,096 KB |
testcase_40 | AC | 186 ms
13,796 KB |
testcase_41 | AC | 477 ms
15,224 KB |
testcase_42 | AC | 456 ms
15,360 KB |
testcase_43 | AC | 503 ms
15,196 KB |
testcase_44 | AC | 535 ms
15,172 KB |
ソースコード
#include <bits/stdc++.h> // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2") #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define yn(joken) cout<<((joken) ? "Yes" : "No")<<"\n" #define YN(joken) cout<<((joken) ? "YES" : "NO")<<"\n" using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vc = vector<char>; using vd = vector<double>; using vld = vector<long double>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; using vvs = vector<vector<string>>; using vvc = vector<vector<char>>; using vvd = vector<vector<double>>; using vvld = vector<vector<long double>>; using vvvi = vector<vector<vector<int>>>; using vvvl = vector<vector<vector<ll>>>; using vvvvi = vector<vector<vector<vector<int>>>>; using vvvvl = vector<vector<vector<vector<ll>>>>; using pii = pair<int,int>; using pll = pair<ll,ll>; const int INF = 1e9; const ll LINF = 2e18; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } bool ispow2(int i) { return i && (i & -i) == i; } bool ispow2(ll i) { return i && (i & -i) == i; } template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < int(v.size()) - 1) os << ' '; } return os; } // segtree<S,op,e> seg(int n)またはsegtree<S,op,e> seg(vector<S> vec)で初期化 // Sは型, Sを返す関数op(S a,S b)と単位元S e()を設定する // set(int p,S x): a[p]にxを代入する // get(int p): a[p]を取得する // prod(int l,int r): [l,r)をfoldした結果を返す // all_prod(): [0,n)をfoldした結果を返す // max_right<f>(int l): bool f(S x)を渡すとl以降でf(prod(l,r))=trueとなる最大のrを返す // min_left: max_rightの逆 int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } template <class S, S (*op)(S, S), S (*e)()> struct segtree{ public: segtree() : segtree(0) {} segtree(int n) : segtree(vector<S>(n, e())) {} segtree(const vector<S> &v) : _n(int(v.size())){ log = ceil_pow2(_n); size = 1 << log; d = vector<S>(2 * size, e()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) update(i); } void set(int p, S x){ assert(0 <= p && p < _n); p += size; d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } S get(int p){ assert(0 <= p && p < _n); return d[p + size]; } S prod(int l, int r){ assert(0 <= l && l <= r && r <= _n); S sml = e(), smr = e(); l += size; r += size; while (l < r){ if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() { return d[1]; } template <bool (*f)(S)> int max_right(int l){ return max_right(l, [](S x) { return f(x); }); } template <class F> int max_right(int l, F f){ assert(0 <= l && l <= _n); assert(f(e())); if (l == _n) return _n; l += size; S sm = e(); do{ while (l % 2 == 0) l >>= 1; if (!f(op(sm, d[l]))){ while (l < size){ l = (2 * l); if (f(op(sm, d[l]))){ sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template <bool (*f)(S)> int min_left(int r){ return min_left(r, [](S x) { return f(x); }); } template <class F> int min_left(int r, F f){ assert(0 <= r && r <= _n); assert(f(e())); if (r == 0) return 0; r += size; S sm = e(); do{ r--; while (r > 1 && (r % 2)) r >>= 1; if (!f(op(d[r], sm))){ while (r < size){ r = (2 * r + 1); if (f(op(d[r], sm))){ sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } private: int _n, size, log; std::vector<S> d; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } }; ll op(ll l,ll r){ return gcd(l,r); } ll e(){ return 0; } void solve(){ ll N; cin>>N; vl A(N); cin>>A; segtree<ll,op,e> seg(A); ll ans=N*(N+1)/2; rep(i,N){ auto f=[&](ll g)->bool{ return g!=1; }; ll r=seg.max_right(i,f); ans-=r-i; } cout<<ans<<endl; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }