結果

問題 No.1036 Make One With GCD 2
ユーザー rabimearabimea
提出日時 2023-02-28 22:24:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,041 bytes
コンパイル時間 3,531 ms
コンパイル使用メモリ 197,596 KB
実行使用メモリ 38,504 KB
最終ジャッジ日時 2023-10-14 04:50:39
合計ジャッジ時間 12,735 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 30 ms
36,800 KB
testcase_03 AC 54 ms
15,668 KB
testcase_04 AC 90 ms
25,632 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 230 ms
37,976 KB
testcase_10 AC 216 ms
35,076 KB
testcase_11 AC 234 ms
38,388 KB
testcase_12 AC 214 ms
35,624 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 3 ms
4,972 KB
testcase_19 AC 3 ms
4,976 KB
testcase_20 AC 4 ms
5,032 KB
testcase_21 AC 4 ms
4,968 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
4,368 KB
testcase_28 AC 2 ms
4,752 KB
testcase_29 AC 2 ms
4,976 KB
testcase_30 AC 2 ms
4,972 KB
testcase_31 AC 2 ms
5,092 KB
testcase_32 AC 2 ms
4,972 KB
testcase_33 AC 2 ms
4,972 KB
testcase_34 AC 2 ms
4,976 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = 20;
int st[LOGN][N];
 
int 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