結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | opt |
提出日時 | 2020-04-25 00:28:26 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 601 ms / 2,000 ms |
コード長 | 3,121 bytes |
コンパイル時間 | 2,627 ms |
コンパイル使用メモリ | 213,636 KB |
実行使用メモリ | 19,304 KB |
最終ジャッジ日時 | 2024-09-16 13:32:10 |
合計ジャッジ時間 | 16,972 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 488 ms
19,184 KB |
testcase_01 | AC | 338 ms
19,164 KB |
testcase_02 | AC | 321 ms
19,228 KB |
testcase_03 | AC | 69 ms
10,204 KB |
testcase_04 | AC | 122 ms
16,496 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 116 ms
10,564 KB |
testcase_08 | AC | 92 ms
9,924 KB |
testcase_09 | AC | 376 ms
19,156 KB |
testcase_10 | AC | 347 ms
18,532 KB |
testcase_11 | AC | 387 ms
19,044 KB |
testcase_12 | AC | 356 ms
18,440 KB |
testcase_13 | AC | 469 ms
18,828 KB |
testcase_14 | AC | 471 ms
18,796 KB |
testcase_15 | AC | 446 ms
18,436 KB |
testcase_16 | AC | 448 ms
18,368 KB |
testcase_17 | AC | 462 ms
18,804 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 3 ms
6,944 KB |
testcase_21 | AC | 4 ms
6,944 KB |
testcase_22 | AC | 437 ms
18,416 KB |
testcase_23 | AC | 316 ms
16,500 KB |
testcase_24 | AC | 455 ms
18,680 KB |
testcase_25 | AC | 414 ms
17,868 KB |
testcase_26 | AC | 425 ms
18,200 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 2 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 407 ms
19,228 KB |
testcase_39 | AC | 467 ms
19,292 KB |
testcase_40 | AC | 326 ms
16,596 KB |
testcase_41 | AC | 597 ms
19,240 KB |
testcase_42 | AC | 579 ms
19,188 KB |
testcase_43 | AC | 563 ms
19,304 KB |
testcase_44 | AC | 601 ms
19,284 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep2(i, m, n) for(int i=int(m); i<int(n); ++i) #define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i) #define rep(i, n) rep2(i, 0, n) #define drep(i, n) drep2(i, n, 0) #define all(a) a.begin(), a.end() using ll = long long; using ld = long double; using V = vector<int>; using Vll = vector<ll>; using Vld = vector<ld>; using Vbo = vector<bool>; using VV = vector<V>; using VVll = vector<Vll>; using VVld = vector<Vld>; using VVbo = vector<Vbo>; using P = pair<int, int>; using Pll = pair<ll, ll>; using Pld = pair<ld, ld>; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; } template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits const int INF = 1<<30; const ll INFll = 1ll<<62; const ld EPS = 1e-10; const int MOD = int(1e9)+7; template<typename T> struct SegmentTree { int m, n; // m: size of original vector, n: size of segment tree vector<T> d; T idt = 0; T op(T &a, T &b) { // return a + b; return gcd(a, b); } SegmentTree(vector<T> v) : m(v.size()) { n = 1; while(n < m) n <<= 1; d.assign(2*n-1, 0); rep(i, m) d[i+n-1] = v[i]; drep(i, n-1) d[i] = op(d[i*2+1], d[i*2+2]); } void add(int k, T val) { k += n-1, d[k] += val; while (k) k = (k-1)/2, d[k] = op(d[2*k+1], d[2*k+2]); } void set(int k, T val) { k += n-1, d[k] = val; while (k) k = (k-1)/2, d[k] = op(d[2*k+1], d[2*k+2]); } T op_range(int a, int b, int k=0, int l=0, int r=-1) { if (r < 0) r = n; if (b <= l || r <= a) return idt; if (a <= l && r <= b) return d[k]; T vl = op_range(a, b, 2*k+1, l, (l+r)/2); T vr = op_range(a, b, 2*k+2, (l+r)/2, r); return op(vl, vr); } T get(int a) { return d[n-1+a]; } vector<T> get_all() { vector<T> res(m); copy(d.begin()+n-1, d.begin()+n+m-1, res.begin()); return res; } }; int main() { ll n; cin >> n; Vll a(n); cin >> a; ll ans = 0; SegmentTree<ll> st(a); int j = 0; rep(i, n) { ll y = st.op_range(i, j+1); while (j < n && st.op_range(i, j+1) > 1) ++j; ans += n-j; if (i == j) ++j; } cout << ans << endl; return 0; }