結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | kcvlex |
提出日時 | 2020-04-24 22:03:19 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,005 ms / 2,000 ms |
コード長 | 3,804 bytes |
コンパイル時間 | 1,864 ms |
コンパイル使用メモリ | 151,744 KB |
実行使用メモリ | 113,664 KB |
最終ジャッジ日時 | 2024-11-07 20:41:47 |
合計ジャッジ時間 | 26,057 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 955 ms
113,664 KB |
testcase_01 | AC | 736 ms
113,664 KB |
testcase_02 | AC | 483 ms
113,664 KB |
testcase_03 | AC | 260 ms
57,984 KB |
testcase_04 | AC | 509 ms
112,256 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 3 ms
5,248 KB |
testcase_07 | AC | 311 ms
58,112 KB |
testcase_08 | AC | 269 ms
57,856 KB |
testcase_09 | AC | 752 ms
113,536 KB |
testcase_10 | AC | 714 ms
113,152 KB |
testcase_11 | AC | 772 ms
113,536 KB |
testcase_12 | AC | 723 ms
113,280 KB |
testcase_13 | AC | 830 ms
113,280 KB |
testcase_14 | AC | 836 ms
113,408 KB |
testcase_15 | AC | 795 ms
113,280 KB |
testcase_16 | AC | 798 ms
113,280 KB |
testcase_17 | AC | 823 ms
113,280 KB |
testcase_18 | AC | 3 ms
5,248 KB |
testcase_19 | AC | 4 ms
5,248 KB |
testcase_20 | AC | 5 ms
5,248 KB |
testcase_21 | AC | 4 ms
5,248 KB |
testcase_22 | AC | 787 ms
113,152 KB |
testcase_23 | AC | 633 ms
112,256 KB |
testcase_24 | AC | 800 ms
113,408 KB |
testcase_25 | AC | 747 ms
113,024 KB |
testcase_26 | AC | 767 ms
113,152 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 2 ms
5,248 KB |
testcase_31 | AC | 3 ms
5,248 KB |
testcase_32 | AC | 2 ms
5,248 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 3 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 2 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | AC | 474 ms
113,536 KB |
testcase_39 | AC | 921 ms
113,664 KB |
testcase_40 | AC | 631 ms
112,256 KB |
testcase_41 | AC | 978 ms
113,536 KB |
testcase_42 | AC | 980 ms
113,664 KB |
testcase_43 | AC | 988 ms
113,664 KB |
testcase_44 | AC | 1,005 ms
113,536 KB |
ソースコード
#include <limits> #include <initializer_list> #include <utility> #include <bitset> #include <tuple> #include <type_traits> #include <functional> #include <string> #include <array> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <iterator> #include <algorithm> #include <complex> #include <random> #include <numeric> #include <iostream> #include <iomanip> #include <sstream> #include <regex> #include <cassert> #include <cstddef> #include <variant> #define endl codeforces #define ALL(v) std::begin(v), std::end(v) #define ALLR(v) std::rbegin(v), std::rend(v) using ll = std::int64_t; using ull = std::uint64_t; using pii = std::pair<int, int>; using tii = std::tuple<int, int, int>; using pll = std::pair<ll, ll>; using tll = std::tuple<ll, ll, ll>; template <typename T> using vec = std::vector<T>; template <typename T> using vvec = vec<vec<T>>; template <typename T> const T& var_min(const T &t) { return t; } template <typename T> const T& var_max(const T &t) { return t; } template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template <typename T> T make_v(T init) { return init; } template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); } template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; }; template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; }; template <typename T, std::size_t... Args> using mdarray = typename multi_dem_array<T, Args...>::type; namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } ssize_t ceil_pow2(ssize_t s) { ssize_t ret = 1; while (ret < s) ret *= 2; return ret; } struct SparseTable { vvec<ll> table; vec<ll> bsz; ll op(ll a, ll b) { return (a && b ? std::gcd(a, b) : std::max(a, b)); } SparseTable(const vec<ll> &av) { ll sz = ceil_pow2(av.size()); table = make_v<ll>(0, sz, 20); bsz.resize(sz + 1); for (ll i = 0, j = 1; j <= sz; i++, j *= 2) bsz[j] = i; for (ll i = 1; i <= sz; i++) chmax(bsz[i], bsz[i - 1]); for (ll i = 0; i < av.size(); i++) table[i][0] = av[i]; for (ll i = 0; i + 1 < 20; i++) for (ll j = 0; j < sz; j++) { ll f = j; ll t = std::min<ll>(sz - 1, f + (1ll << i)); table[j][i + 1] = op(table[j][i], table[t][i]); } } ll query(ll l, ll r) { ll len = r - l; ll idx = bsz[len]; ll offset = 1ll << idx; return op(table[l][idx], table[r - offset][idx]); } }; int main() { ll n; std::cin >> n; vec<ll> av(n); for (ll &e : av) std::cin >> e; SparseTable table(av); ll ans = 0; for (ll i = 0; i < n; i++) { if (1 < table.query(i, n)) break; ll ok = n, ng = i; while (1 < std::abs(ok - ng)) { ll mid = (ok + ng) / 2; (table.query(i, mid) == 1 ? ok : ng) = mid; } ans += n - ng; } std::cout << ans << '\n'; return 0; }