結果
問題 | No.1036 Make One With GCD 2 |
ユーザー |
![]() |
提出日時 | 2020-04-24 21:30:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 320 ms / 2,000 ms |
コード長 | 1,262 bytes |
コンパイル時間 | 2,284 ms |
コンパイル使用メモリ | 199,664 KB |
最終ジャッジ日時 | 2025-01-09 23:13:52 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef LOCAL#include "debug.h"#else#define DEBUG(...)#endifint ctz(int a) { return __builtin_ctz(a); }int ctz(long long a) { return __builtin_ctzll(a); }template <class T> T gcd(T a, T b) {a = abs(a), b = abs(b);if (a == 0) return b;int k = ctz(a | b);a >>= ctz(a);while (b) {b >>= ctz(b);if (a > b) swap(a, b);b -= a;}return a << k;}template <class T> struct sparse_table {vector<vector<T>> t;sparse_table(const vector<T>& v = {}) : t{v} {for (int k = 1, n = v.size(); 1 << k <= n; ++k) {t.emplace_back(n - (1 << k) + 1);for (int i = 0; i + (1 << k) <= n; ++i)t[k][i] = gcd(t[k - 1][i], t[k - 1][i + (1 << (k - 1))]);}}T fold(int l, int r) const {assert(l < r);int k = __lg(r - l);return gcd(t[k][l], t[k][r - (1 << k)]);}};int main() {cin.tie(nullptr);ios::sync_with_stdio(false);int n;cin >> n;vector<long long> a(n);for (auto&& e : a) {cin >> e;}sparse_table st(a);auto res = (long long)n * (n + 1) / 2;for (int l = 0, r = 0; l < n; ++l) {while (r <= l or (r <= n and st.fold(l, r) > 1)) {++r;}res -= r - l - 1;}cout << res << '\n';}