結果

問題 No.1036 Make One With GCD 2
ユーザー rabimearabimea
提出日時 2023-02-28 22:26:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 444 ms / 2,000 ms
コード長 1,039 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 198,788 KB
実行使用メモリ 77,268 KB
最終ジャッジ日時 2023-10-14 04:52:25
合計ジャッジ時間 13,587 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 444 ms
77,136 KB
testcase_01 AC 232 ms
77,116 KB
testcase_02 AC 156 ms
77,072 KB
testcase_03 AC 61 ms
64,184 KB
testcase_04 AC 102 ms
75,156 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 100 ms
68,556 KB
testcase_08 AC 83 ms
64,084 KB
testcase_09 AC 245 ms
77,096 KB
testcase_10 AC 229 ms
77,120 KB
testcase_11 AC 251 ms
77,108 KB
testcase_12 AC 231 ms
77,124 KB
testcase_13 AC 327 ms
77,056 KB
testcase_14 AC 331 ms
77,060 KB
testcase_15 AC 308 ms
77,044 KB
testcase_16 AC 311 ms
77,268 KB
testcase_17 AC 321 ms
77,060 KB
testcase_18 AC 6 ms
23,876 KB
testcase_19 AC 7 ms
25,924 KB
testcase_20 AC 7 ms
27,976 KB
testcase_21 AC 7 ms
25,984 KB
testcase_22 AC 307 ms
77,056 KB
testcase_23 AC 229 ms
75,008 KB
testcase_24 AC 318 ms
77,052 KB
testcase_25 AC 289 ms
75,012 KB
testcase_26 AC 300 ms
77,060 KB
testcase_27 AC 2 ms
5,392 KB
testcase_28 AC 2 ms
7,584 KB
testcase_29 AC 3 ms
7,524 KB
testcase_30 AC 3 ms
9,604 KB
testcase_31 AC 5 ms
19,720 KB
testcase_32 AC 5 ms
19,752 KB
testcase_33 AC 4 ms
13,648 KB
testcase_34 AC 5 ms
19,768 KB
testcase_35 AC 2 ms
5,464 KB
testcase_36 AC 2 ms
7,472 KB
testcase_37 AC 3 ms
9,536 KB
testcase_38 AC 152 ms
77,092 KB
testcase_39 AC 412 ms
77,136 KB
testcase_40 AC 228 ms
75,020 KB
testcase_41 AC 413 ms
77,060 KB
testcase_42 AC 401 ms
77,072 KB
testcase_43 AC 407 ms
77,100 KB
testcase_44 AC 434 ms
77,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
using vi = vector <int>;
using pii = pair <int, int>;
const ll mod = 998244353;
//~ const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 5e5 + 11;
const int LOGN = 22;
ll st[LOGN][N];
 
ll query(int l, int r) {
	int b = __lg(r - l + 1);
	return gcd(st[b][l], st[b][r - (1 << b) + 1]);
}
 
int main() {
	ios::sync_with_stdio(0);
	
	int n; cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> st[0][i];
	
	for(int k = 1; k < LOGN; k ++) {
		for(int i = 1; i <= n; i ++)
			if(i + (1 << k) <= n + 1) {
				st[k][i] = gcd(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]);
			}
	}
	
	ll ans = 0;
	
	for(int i = 1; i <= n; i ++) {
		if(query(i, n) == 1) {
			int l = i, r = n + 1;
			while(l + 1 < r) {
				int m = (l + r) / 2;
				if(query(i, m - 1) == 1)
					r = m;
				else
					l = m;
			}
			
			ans += n - l + 1;
		}
	}
	
	cout << ans << '\n';
}
0