結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
veqcc
|
| 提出日時 | 2020-04-24 22:02:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,673 bytes |
| コンパイル時間 | 1,332 ms |
| コンパイル使用メモリ | 109,268 KB |
| 実行使用メモリ | 15,508 KB |
| 最終ジャッジ日時 | 2024-11-07 02:24:07 |
| 合計ジャッジ時間 | 18,946 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 13 WA * 28 |
ソースコード
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
template <typename T>
class SegmentTree {
using F = function<T(T, T)>;
int n;
F f;
T t;
vector <T> dat;
public:
SegmentTree(F f, T t) : f(f), t(t) {}
void init(int n_) {
n = 1;
while (n < n_) n <<= 1;
dat.assign(n << 1, t);
}
void build(const vector <T> &v) {
auto n_ = (int)v.size();
init(n_);
for (int i = 0; i < n_; i++) dat[n + i] = v[i];
for (int i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
void set_val(int k, T x) {
dat[k += n] = x;
while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
}
T query(int a, int b) {
T vl = t, vr = t;
for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
if (l & 1) vl = f(vl, dat[l++]);
if (r & 1) vr = f(dat[--r], vr);
}
return f(vl, vr);
}
};
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
int main() {
int n;
cin >> n;
vector <ll> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
SegmentTree<ll> seg(gcd, 0);
seg.build(a);
ll ans = n * (n + 1) / 2;
int r = 1;
for (int l = 0; l < n; l++) {
while (r <= n && seg.query(l, r) != 1) r++;
ans -= r - l - 1;
}
cout << ans << "\n";
return 0;
}
veqcc