結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | minato |
提出日時 | 2020-07-08 03:10:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 748 ms / 2,000 ms |
コード長 | 3,442 bytes |
コンパイル時間 | 3,731 ms |
コンパイル使用メモリ | 236,440 KB |
実行使用メモリ | 15,492 KB |
最終ジャッジ日時 | 2024-04-10 03:41:31 |
合計ジャッジ時間 | 17,503 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 748 ms
15,380 KB |
testcase_01 | AC | 174 ms
15,428 KB |
testcase_02 | AC | 186 ms
15,492 KB |
testcase_03 | AC | 30 ms
8,776 KB |
testcase_04 | AC | 51 ms
14,000 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 65 ms
8,960 KB |
testcase_08 | AC | 54 ms
8,700 KB |
testcase_09 | AC | 223 ms
15,224 KB |
testcase_10 | AC | 198 ms
14,808 KB |
testcase_11 | AC | 221 ms
15,400 KB |
testcase_12 | AC | 199 ms
15,088 KB |
testcase_13 | AC | 329 ms
15,100 KB |
testcase_14 | AC | 339 ms
15,188 KB |
testcase_15 | AC | 311 ms
14,896 KB |
testcase_16 | AC | 317 ms
15,100 KB |
testcase_17 | AC | 327 ms
15,148 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 3 ms
6,944 KB |
testcase_21 | AC | 3 ms
6,944 KB |
testcase_22 | AC | 315 ms
14,876 KB |
testcase_23 | AC | 233 ms
13,960 KB |
testcase_24 | AC | 324 ms
15,036 KB |
testcase_25 | AC | 295 ms
14,744 KB |
testcase_26 | AC | 313 ms
14,676 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 1 ms
6,940 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,944 KB |
testcase_32 | AC | 1 ms
6,940 KB |
testcase_33 | AC | 1 ms
6,944 KB |
testcase_34 | AC | 2 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 1 ms
6,940 KB |
testcase_38 | AC | 176 ms
15,260 KB |
testcase_39 | AC | 577 ms
15,348 KB |
testcase_40 | AC | 241 ms
13,848 KB |
testcase_41 | AC | 493 ms
15,400 KB |
testcase_42 | AC | 471 ms
15,348 KB |
testcase_43 | AC | 500 ms
15,336 KB |
testcase_44 | AC | 528 ms
15,200 KB |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using u64 = uint_fast64_t; using pii = pair<int, int>; using pll = pair<long long, long long>; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() constexpr char ln = '\n'; constexpr long long MOD = 1000000007; //constexpr long long MOD = 998244353; template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; } template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; } inline int popcount(int x) {return __builtin_popcount(x);} inline int popcount(long long x) {return __builtin_popcountll(x);} void print() { cout << "\n"; } template<class T, class... Args> void print(const T &x, const Args &... args) { cout << x << " "; print(args...); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// template<typename T, typename Monoid> struct SegmentTree { Monoid merge; T unity; int N; vector<T> node; SegmentTree(Monoid f, T id) : merge(f), unity(id) {} void init(int sz) { N = 1; while (N < sz) N <<= 1; node.assign(2*N,unity); } void set(int k, const T &val) {node[k+N] = val;} void build() { for (int i = N-1; i > 0; --i) { node[i] = merge(node[i<<1|0], node[i<<1|1]); } } // (0-indexed) void update(int x, T val) { x += N; node[x] = val; while (x > 1) { x >>= 1; node[x] = merge(node[x<<1|0], node[x<<1|1]); } } // [l, r) (0-indexed) T get(int l, int r) { if (l >= r) return unity; T resl = unity, resr = unity; l += N; r += N; while (l < r) { if (l & 1) resl = merge(resl, node[l++]); l >>= 1; if (r & 1) resr = merge(node[--r], resr); r >>= 1; } return merge(resl, resr); } template<typename C> int binarysearch(int s, const C &check, T &acc, int k, int l, int r) { if (r-l==1) { acc = merge(acc,node[k]); return check(acc) ? k - N : -1; } int m = (l+r)>>1; if(m <= s) return binarysearch(s, check, acc, (k<<1)|1, m, r); if(s <= l && !check(merge(acc,node[k]))) { acc = merge(acc,node[k]); return -1; } int vl = binarysearch(s, check, acc, (k<<1)|0, l, m); if(~vl) return vl; return binarysearch(s, check, acc, (k<<1)|1, m, r); } template<typename C> int binarysearch(int s, const C &check) { T acc = unity; return binarysearch(s, check, acc, 1, 0, N); } T operator[](int x) {return node[x+N];} }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<ll> A(N); rep(i,N) cin >> A[i]; auto f=[](ll a, ll b) {return gcd(a,b);}; const ll id = 0; SegmentTree seg(f,id); seg.init(N); rep(i,N) seg.set(i,A[i]); seg.build(); auto check=[](ll x) {return x==1;}; ll ans = 0; rep(i,N) { int k = seg.binarysearch(i,check); if (k==-1) continue; ans += N-k; } cout << ans << ln; }