結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | Example |
提出日時 | 2020-04-25 10:54:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,479 ms / 2,000 ms |
コード長 | 7,992 bytes |
コンパイル時間 | 2,024 ms |
コンパイル使用メモリ | 140,808 KB |
実行使用メモリ | 25,892 KB |
最終ジャッジ日時 | 2024-09-16 13:39:46 |
合計ジャッジ時間 | 23,929 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 832 ms
25,856 KB |
testcase_01 | AC | 394 ms
25,720 KB |
testcase_02 | AC | 371 ms
25,728 KB |
testcase_03 | AC | 105 ms
13,536 KB |
testcase_04 | AC | 176 ms
19,072 KB |
testcase_05 | AC | 19 ms
6,400 KB |
testcase_06 | AC | 19 ms
6,272 KB |
testcase_07 | AC | 152 ms
14,700 KB |
testcase_08 | AC | 126 ms
13,304 KB |
testcase_09 | AC | 523 ms
25,472 KB |
testcase_10 | AC | 487 ms
24,168 KB |
testcase_11 | AC | 531 ms
25,772 KB |
testcase_12 | AC | 492 ms
24,152 KB |
testcase_13 | AC | 658 ms
24,960 KB |
testcase_14 | AC | 662 ms
25,144 KB |
testcase_15 | AC | 619 ms
23,808 KB |
testcase_16 | AC | 627 ms
24,128 KB |
testcase_17 | AC | 648 ms
24,496 KB |
testcase_18 | AC | 20 ms
6,272 KB |
testcase_19 | AC | 20 ms
6,272 KB |
testcase_20 | AC | 21 ms
6,528 KB |
testcase_21 | AC | 20 ms
6,528 KB |
testcase_22 | AC | 614 ms
23,804 KB |
testcase_23 | AC | 455 ms
19,072 KB |
testcase_24 | AC | 637 ms
24,448 KB |
testcase_25 | AC | 583 ms
22,768 KB |
testcase_26 | AC | 606 ms
23,524 KB |
testcase_27 | AC | 19 ms
6,400 KB |
testcase_28 | AC | 19 ms
6,400 KB |
testcase_29 | AC | 19 ms
6,400 KB |
testcase_30 | AC | 19 ms
6,400 KB |
testcase_31 | AC | 19 ms
6,272 KB |
testcase_32 | AC | 19 ms
6,528 KB |
testcase_33 | AC | 19 ms
6,400 KB |
testcase_34 | AC | 19 ms
6,400 KB |
testcase_35 | AC | 19 ms
6,400 KB |
testcase_36 | AC | 19 ms
6,400 KB |
testcase_37 | AC | 19 ms
6,400 KB |
testcase_38 | AC | 631 ms
25,856 KB |
testcase_39 | AC | 1,479 ms
25,856 KB |
testcase_40 | AC | 460 ms
19,200 KB |
testcase_41 | AC | 1,146 ms
25,892 KB |
testcase_42 | AC | 1,121 ms
25,856 KB |
testcase_43 | AC | 1,089 ms
25,872 KB |
testcase_44 | AC | 1,153 ms
25,856 KB |
ソースコード
#include <iostream> #include <cstdio> #include <string> #include <vector> #include <algorithm> #include <functional> #include <iomanip> #include <stdlib.h> #include <string.h> #include <cstring> #include <cmath> #include <map> #include <queue> #include <deque> #include <stack> #include <set> #include <stdio.h> #include <tuple> #include <bitset> #include <cfloat> #include <fstream> #include <limits.h> #include <list> #include <math.h> #include <random> #include <unordered_map> #include <unordered_set> #include <bitset> #include <numeric> #include <utility> #include <sstream> #include <cassert> template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair<ll, ll> #define sz(x) (ll)x.size() #define ALL(x) (x).begin(),(x).end() #define ALLR(x) (x).rbegin(),(x).rend() #define VE vector<ll> #define COUT(x) cout<<(x)<<endl #define MA map<ll,ll> #define SE set<ll> #define PQ priority_queue<ll> #define PQR priority_queue<ll,VE,greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define EPS (1e-14) #define pb push_back long long MOD = 1000000007; //const long long MOD = 998244353; const long long INF = 1LL << 60; const double PI = acos(-1.0); struct mint { ll x; // typedef long long ll; mint(ll x = 0) :x((x%MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; istream& operator>>(istream& is, const mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } struct combination { vector<mint> fact, ifact; combination(int n) :fact(n + 1), ifact(n + 1) { assert(n < MOD); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }com(200010); struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) :n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; template<class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n%i == 0)return false; } return n != 1; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector<pair<char, int>> RunLength(string s) { if (s.size() == 0)return {}; vector<pair<char, int>>res(1, pair<char, int>(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1)cnt++; n /= 2; } return cnt; } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N / i != i) res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } const ll dx[4] = { 1,0,-1,0 }; const ll dy[4] = { 0,1,0,-1 }; struct edge { ll to, cost; }; typedef long double ld; using Graph = vector<VE>; class UnionFind { public: vector <ll> par; // 各元の親を表す配列 vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.resize(sz_, 1); for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; template <typename X> struct SegTree { using FX = function<X(X, X)>; int n; FX fx; const X ex; vector<X> dat; SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) { int x = 1; while (n_ > x) { x *= 2; } n = x; } void set(int i, X x) { dat[i + n - 1] = x; } void build() { for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]); } void update(int i, X x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; // parent dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]); } } // the minimum element of [a,b) X query(int a, int b) { return query_sub(a, b, 0, 0, n); } X query_sub(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return ex; } else if (a <= l && r <= b) { return dat[k]; } else { X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return fx(vl, vr); } } /* debug */ inline X operator[](int a) { return query(a, a + 1); } void print() { for (int i = 0; i < n; ++i) { cout << (*this)[i]; if (i != n) cout << ","; } cout << endl; } }; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //cout << fixed << setprecision(15); int n; cin >> n; using X = int; X ex = numeric_limits<int>::max(); auto fx = [ex](X x1, X x2) -> X { return (x1 == ex) ? x2 : ((x2 == ex) ? x1 : gcd(x1, x2)); }; SegTree<X> segGcd(n, fx, ex); VE a(n); rep(i, n)cin >> a[i]; rep(i, n) { segGcd.update(i, a[i]); } int ans = 0; int right = 0; rep(left, n) { if (left > right)right = left; while (right < n && segGcd.query(left, right + 1)>1) { right++; } ans += n - right; } cout << ans << endl; return 0; }