結果

問題 No.1036 Make One With GCD 2
ユーザー knshnbknshnb
提出日時 2020-04-25 22:25:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 2,883 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 204,648 KB
実行使用メモリ 15,132 KB
最終ジャッジ日時 2023-10-14 20:09:38
合計ジャッジ時間 10,732 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 190 ms
14,744 KB
testcase_01 AC 144 ms
14,968 KB
testcase_02 AC 171 ms
14,668 KB
testcase_03 AC 16 ms
7,204 KB
testcase_04 AC 26 ms
10,604 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 48 ms
8,048 KB
testcase_08 AC 40 ms
7,048 KB
testcase_09 AC 171 ms
14,324 KB
testcase_10 AC 159 ms
13,640 KB
testcase_11 AC 174 ms
14,764 KB
testcase_12 AC 160 ms
13,876 KB
testcase_13 AC 285 ms
14,156 KB
testcase_14 AC 290 ms
14,440 KB
testcase_15 AC 271 ms
13,708 KB
testcase_16 AC 275 ms
13,596 KB
testcase_17 AC 283 ms
14,244 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,356 KB
testcase_22 AC 268 ms
13,400 KB
testcase_23 AC 198 ms
10,784 KB
testcase_24 AC 279 ms
13,776 KB
testcase_25 AC 256 ms
12,988 KB
testcase_26 AC 266 ms
13,620 KB
testcase_27 AC 2 ms
4,372 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 1 ms
4,356 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 1 ms
4,352 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 2 ms
4,372 KB
testcase_38 AC 167 ms
14,696 KB
testcase_39 AC 186 ms
14,752 KB
testcase_40 AC 198 ms
10,780 KB
testcase_41 AC 227 ms
15,132 KB
testcase_42 AC 226 ms
14,852 KB
testcase_43 AC 228 ms
14,660 KB
testcase_44 AC 232 ms
14,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "1036_segment_tree.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/1036"

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Apr 25 22:22:21 JST 2020
 **/

#define CALL_FROM_TEST
#line 1 "/Users/knshnb/competitive_programming/competitive_library/src/Datastructure/SegmentTree.hpp"
/// @docs src/DataStructure/SegmentTree.md
template <class T, class F> struct SegmentTree {
    const F op;
    const T e;
    SegmentTree(F op_, T e_) : op(op_), e(e_) {}
    int n;
    std::vector<T> t;
    void set_by_identity(int n_) {
        n = n_;
        t.clear(), t.resize(2 * n, e);
    }
    void set_by_vector(const std::vector<T>& a) {
        n = a.size();
        t.clear(), t.resize(2 * n, e);
        for (int i = 0; i < n; i++) t[i + n] = a[i];
        build();
    }
    void build() {
        for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    T& operator[](int i) { return t[i + n]; }
    // [l, r)
    T query(int l, int r) const {
        assert(0 <= l && l <= r && r <= n);
        T resl = e, resr = e;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, t[l++]);
            if (r & 1) resr = op(t[--r], resr);
        }
        return op(resl, resr);
    }
    // i番目をxに変更
    void update(int i, const T& x) {
        assert(0 <= i && i < n);
        t[i += n] = x;
        while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    // i番目にxを作用 (a[i] = op(a[i], x))
    void operate(int i, const T& x) {
        assert(0 <= i && i < n);
        i += n;
        t[i] = op(t[i], x);
        while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    friend std::string to_string(const SegmentTree<T, F>& seg) {
        return to_string(std::vector<T>(seg.t.begin() + seg.n, seg.t.end()));
    }
};
template <class T, class F> auto make_segment_tree(F op, T e) { return SegmentTree<T, F>(op, e); }
#line 19 "1036_segment_tree.test.cpp"
#undef CALL_FROM_TEST

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    auto seg = make_segment_tree<Int>([](Int x, Int y) { return std::gcd(x, y); }, 0);
    seg.set_by_vector(a);
    Int ans = 0, j = 0;
    REP(i, n) {
        j = std::max(i, j);
        Int acc = seg.query(i, j);
        while (j < n && (acc = std::gcd(acc, a[j])) != 1) {
            j++;
        }
        ans += n - j;
    }
    std::cout << ans << std::endl;
}
0