結果

問題 No.1036 Make One With GCD 2
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-04-25 00:59:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 904 ms / 2,000 ms
コード長 2,949 bytes
コンパイル時間 2,418 ms
コンパイル使用メモリ 203,712 KB
実行使用メモリ 109,292 KB
最終ジャッジ日時 2023-10-14 19:36:54
合計ジャッジ時間 19,764 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 439 ms
109,088 KB
testcase_01 AC 237 ms
109,224 KB
testcase_02 AC 251 ms
109,220 KB
testcase_03 AC 83 ms
54,620 KB
testcase_04 AC 136 ms
105,000 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 107 ms
55,432 KB
testcase_08 AC 96 ms
54,452 KB
testcase_09 AC 473 ms
109,088 KB
testcase_10 AC 443 ms
108,148 KB
testcase_11 AC 477 ms
109,140 KB
testcase_12 AC 446 ms
108,092 KB
testcase_13 AC 720 ms
108,660 KB
testcase_14 AC 737 ms
108,728 KB
testcase_15 AC 698 ms
108,140 KB
testcase_16 AC 695 ms
107,984 KB
testcase_17 AC 718 ms
108,468 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 3 ms
4,352 KB
testcase_20 AC 4 ms
4,812 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 AC 677 ms
107,720 KB
testcase_23 AC 522 ms
105,284 KB
testcase_24 AC 701 ms
108,224 KB
testcase_25 AC 651 ms
107,508 KB
testcase_26 AC 670 ms
107,780 KB
testcase_27 AC 2 ms
4,356 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,368 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 240 ms
109,248 KB
testcase_39 AC 904 ms
109,080 KB
testcase_40 AC 519 ms
105,684 KB
testcase_41 AC 425 ms
109,060 KB
testcase_42 AC 430 ms
109,164 KB
testcase_43 AC 389 ms
109,144 KB
testcase_44 AC 411 ms
109,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }
#ifdef _MSC_VER
inline unsigned int __builtin_clz(unsigned int x){unsigned long r;_BitScanReverse(&r,x);return 31-r;}
#endif // _MSC_VER
template<class V> struct SparseTable { // [L,R)
    const V def = 0;
    inline V comp(V a, V b) { return gcd(a,b); }

    int n; vector<V> a, b[22]; inline int __lg(int x) { return 32 - 1 - __builtin_clz(x); }
    void init(vector<V> v) {
        int nn = v.size(); n = 1; while (n < nn) n *= 2; a.resize(n);
        rep(i, 0, 22) b[i].resize(n); rep(i, 0, nn) a[i] = v[i];

        int d = 1 << __lg(n - 1), e = d << 1;
        for (int h = 0, f; (f = 1 << h) <= d; ++h) {
            for (int i = f, r = f << 1; i < e; i += r) {
                b[h][i - 1] = a[i - 1];
                for (int j = i - 2; j >= i - f; --j) b[h][j] = comp(b[h][j + 1], a[j]);
                b[h][i] = a[i];
                for (int j = i + 1; j < i + f; ++j) b[h][j] = comp(b[h][j - 1], a[j]);
            }
        }
    }

    V get(int L,int R){assert(0<=L&&L<=R);if(L==R)return def;R--;if(L==R)return a[L];int h=__lg(L^R);
        return comp(b[h][L],b[h][R]);}};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N; ll A[501010];
SparseTable<ll> st;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    vector<ll> v;
    rep(i, 0, N) v.push_back(A[i]);
    st.init(v);

    ll ans = 1LL * N * (N - 1) / 2 + N;
    int R = 0;
    rep(L, 0, N) {
        chmax(R, L);
        while (R < N && 1 < st.get(L, R + 1)) R++;
        ans -= R - L;
    }
    cout << ans << endl;
}





0