結果

問題 No.1036 Make One With GCD 2
ユーザー ゆきのんゆきのん
提出日時 2020-04-25 00:04:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,758 bytes
コンパイル時間 1,889 ms
コンパイル使用メモリ 169,864 KB
実行使用メモリ 89,344 KB
最終ジャッジ日時 2024-04-25 10:24:58
合計ジャッジ時間 29,610 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 568 ms
89,088 KB
testcase_01 AC 474 ms
89,216 KB
testcase_02 AC 588 ms
89,088 KB
testcase_03 AC 130 ms
43,648 KB
testcase_04 AC 243 ms
87,936 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 194 ms
43,904 KB
testcase_08 AC 161 ms
43,520 KB
testcase_09 AC 581 ms
89,216 KB
testcase_10 AC 540 ms
88,704 KB
testcase_11 AC 596 ms
89,088 KB
testcase_12 AC 552 ms
88,960 KB
testcase_13 AC 840 ms
88,960 KB
testcase_14 AC 846 ms
88,960 KB
testcase_15 AC 754 ms
88,704 KB
testcase_16 AC 760 ms
88,704 KB
testcase_17 AC 792 ms
88,832 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 751 ms
88,704 KB
testcase_23 AC 571 ms
87,808 KB
testcase_24 AC 786 ms
88,832 KB
testcase_25 AC 735 ms
88,576 KB
testcase_26 AC 748 ms
88,704 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 582 ms
89,088 KB
testcase_39 AC 629 ms
89,088 KB
testcase_40 AC 561 ms
87,808 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


template< typename T >
struct SparseTable
{
    vector< vector< T > > st;

    SparseTable() {}

    SparseTable(const vector< T > &v)
    {
        int b = 0;
        while((1 << b) <= v.size()) ++b;
        st.assign(b, vector< T >(1 << b));
        for(int i = 0; i < v.size(); i++) {
            st[0][i] = v[i];
        }
        for(int i = 1; i < b; i++) {
            for(int j = 0; j + (1 << i) <= (1 << b); j++) {
                st[i][j] = gcd(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
            }
        }
    }

    inline T rmq(int l, int r) // [l, r)
    {
        int b = 32 - __builtin_clz(r - l) - 1;
        return (gcd(st[b][l], st[b][r - (1 << b)]));
    }
};

int main(){
    int n;cin >> n;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    SparseTable<LL> st(a);
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        int l = i, r = n + 1;
        while(abs(r - l) > 1) {
            int m = (r + l) / 2;
            if(st.rmq(i, m) != 1) l = m;
            else r = m;
        }
        ans += n - l;
    }
    cout << ans << endl;
    return 0;
}
0