結果
問題 | No.1036 Make One With GCD 2 |
ユーザー |
|
提出日時 | 2024-03-30 15:56:02 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 671 bytes |
コンパイル時間 | 5,451 ms |
コンパイル使用メモリ | 163,424 KB |
実行使用メモリ | 15,360 KB |
最終ジャッジ日時 | 2024-09-30 17:33:20 |
合計ジャッジ時間 | 54,777 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 TLE * 7 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/segtree>using namespace atcoder;using namespace std;using ll = long long;ll op(ll a, ll b) {return gcd(a, b);}ll e() {return 0LL;}int main() {int N;cin >> N;vector<ll> A(N + 1, 0);for (int i = 1;i <= N;i++) cin >> A[i];segtree<ll, op, e> seg(A);ll ans = 0;for (int i = 1;i <= N;i++) {int ok = i;int ng = N +1;if (A[i] == 1) {ans += N - i + 1;continue;}while (ng - ok > 1) {int m = (ok + ng) / 2;ll g = seg.prod(i, m + 1);if (g == 1) {ng = m;} else {ok = m;}}if (ok == i) {ans += N - i;} else {ans += N - ok;}}cout << ans << endl;}