結果

問題 No.1036 Make One With GCD 2
ユーザー ゆきのんゆきのん
提出日時 2020-04-25 00:03:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,766 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 172,968 KB
実行使用メモリ 97,748 KB
最終ジャッジ日時 2023-08-07 16:42:56
合計ジャッジ時間 27,067 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 585 ms
89,020 KB
testcase_01 AC 491 ms
89,016 KB
testcase_02 AC 605 ms
88,892 KB
testcase_03 AC 140 ms
43,464 KB
testcase_04 AC 247 ms
87,580 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 211 ms
43,592 KB
testcase_08 AC 178 ms
43,308 KB
testcase_09 AC 607 ms
88,964 KB
testcase_10 AC 567 ms
88,488 KB
testcase_11 AC 619 ms
89,048 KB
testcase_12 AC 572 ms
88,704 KB
testcase_13 AC 844 ms
88,684 KB
testcase_14 AC 854 ms
88,996 KB
testcase_15 AC 802 ms
88,552 KB
testcase_16 AC 808 ms
88,476 KB
testcase_17 AC 831 ms
88,736 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 794 ms
88,536 KB
testcase_23 AC 595 ms
87,416 KB
testcase_24 AC 824 ms
88,560 KB
testcase_25 AC 756 ms
88,224 KB
testcase_26 AC 779 ms
88,572 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 590 ms
89,052 KB
testcase_39 AC 620 ms
89,000 KB
testcase_40 AC 595 ms
87,516 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 += max(0, n - l);
    }
    cout << ans << endl;
    return 0;
}
0