結果

問題 No.1036 Make One With GCD 2
ユーザー ゆにぽけゆにぽけ
提出日時 2023-10-25 14:40:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 835 ms / 2,000 ms
コード長 2,314 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 132,004 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2023-10-25 14:41:02
合計ジャッジ時間 14,581 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 441 ms
15,360 KB
testcase_01 AC 90 ms
15,360 KB
testcase_02 AC 174 ms
15,360 KB
testcase_03 AC 20 ms
8,700 KB
testcase_04 AC 32 ms
14,108 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 36 ms
8,964 KB
testcase_08 AC 30 ms
8,704 KB
testcase_09 AC 210 ms
15,360 KB
testcase_10 AC 194 ms
15,096 KB
testcase_11 AC 225 ms
15,360 KB
testcase_12 AC 206 ms
15,096 KB
testcase_13 AC 353 ms
15,096 KB
testcase_14 AC 354 ms
15,096 KB
testcase_15 AC 347 ms
15,096 KB
testcase_16 AC 327 ms
15,096 KB
testcase_17 AC 348 ms
15,096 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 342 ms
14,832 KB
testcase_23 AC 235 ms
14,108 KB
testcase_24 AC 335 ms
15,096 KB
testcase_25 AC 308 ms
14,648 KB
testcase_26 AC 336 ms
14,912 KB
testcase_27 AC 2 ms
4,372 KB
testcase_28 AC 2 ms
4,372 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 1 ms
4,372 KB
testcase_31 AC 2 ms
4,372 KB
testcase_32 AC 2 ms
4,372 KB
testcase_33 AC 2 ms
4,372 KB
testcase_34 AC 2 ms
4,372 KB
testcase_35 AC 1 ms
4,372 KB
testcase_36 AC 2 ms
4,372 KB
testcase_37 AC 1 ms
4,372 KB
testcase_38 AC 342 ms
15,360 KB
testcase_39 AC 835 ms
15,360 KB
testcase_40 AC 239 ms
14,108 KB
testcase_41 AC 593 ms
15,360 KB
testcase_42 AC 588 ms
15,360 KB
testcase_43 AC 549 ms
15,360 KB
testcase_44 AC 615 ms
15,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
#include<atcoder/segtree>
using namespace std;
template<class T,T (*op)(T,T),T (*e)()> struct SegmentTree
{
    private:
    int siz;
    vector<T> node;

    public:
    SegmentTree(int n) noexcept
    {
        siz = 1;
        while(siz < n) siz <<= 1;

        node.assign(2*siz-1,e());
    }

    void replace(int pos,T x) noexcept {func_update(pos,x,[](T u,T v){return u = v;});}

    void add(int pos,T x) noexcept {func_update(pos,x,[](T u,T v){return u+v;});}

    void func_update(int pos,T x) noexcept {func_update(pos,x,op);}
    
    void func_update(int pos,T x,T (*func)(T,T)) noexcept
    {
        assert(0 <= pos && pos < siz);
        pos += siz - 1;

        node[pos] = func(node[pos],x);

        while(pos)
        {
            pos = (pos-1)/2;
            node[pos] = op(node[2*pos+1],node[2*pos+2]);
        }
    }

    T operator [](int pos) noexcept
    {
        assert(0 <= pos && pos < siz);
        return node[pos+siz-1];
    }

    T prod(int l,int r) noexcept
    {
        assert(0 <= l && l <= r && r <= siz);

        l += siz-1;
        r += siz-1;

        T Lval = e();
        T Rval = e();

        while(l < r)
        {
            if(!(l & 1)) Lval = op(Lval,node[l++]);
            if(!(r & 1)) Rval = op(node[--r],Rval);

            l >>= 1;
            r >>= 1;
        }

        return op(Lval,Rval);
    }

    T prod() noexcept {return node[0];}
};
long long op(long long a,long long b)
{
	while(b)
	{
		a %= b;
		swap(a,b);
	}
	return a;
}
long long e() {return 0;}
int N;
void solve()
{
	cin >> N;
	vector<long long> A(N);
	for(int i = 0;i < N;i++) cin >> A[i];
	atcoder::segtree<long long,op,e> seg(A);
	long long ans = 0;
	int ri = 0;
	for(int i = 0;i < N;i++)
	{
		while(ri <= N)
		{
			long long g = seg.prod(i,ri);
			if(g == 1) break;
			else ri++;
		}
		ans += N-ri+1;
	}
	cout << ans << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
}
0