結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | ningenMe |
提出日時 | 2020-04-25 19:15:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 864 ms / 2,000 ms |
コード長 | 3,720 bytes |
コンパイル時間 | 1,662 ms |
コンパイル使用メモリ | 176,344 KB |
実行使用メモリ | 31,784 KB |
最終ジャッジ日時 | 2024-09-16 13:54:03 |
合計ジャッジ時間 | 14,144 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 451 ms
31,784 KB |
testcase_01 | AC | 102 ms
31,772 KB |
testcase_02 | AC | 192 ms
31,684 KB |
testcase_03 | AC | 24 ms
16,944 KB |
testcase_04 | AC | 39 ms
30,316 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 42 ms
17,004 KB |
testcase_08 | AC | 34 ms
16,828 KB |
testcase_09 | AC | 231 ms
31,592 KB |
testcase_10 | AC | 216 ms
31,488 KB |
testcase_11 | AC | 235 ms
31,672 KB |
testcase_12 | AC | 218 ms
31,352 KB |
testcase_13 | AC | 373 ms
31,600 KB |
testcase_14 | AC | 378 ms
31,632 KB |
testcase_15 | AC | 356 ms
31,292 KB |
testcase_16 | AC | 359 ms
31,408 KB |
testcase_17 | AC | 369 ms
31,544 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 3 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 352 ms
31,320 KB |
testcase_23 | AC | 266 ms
30,328 KB |
testcase_24 | AC | 364 ms
31,416 KB |
testcase_25 | AC | 333 ms
31,092 KB |
testcase_26 | AC | 343 ms
31,216 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,944 KB |
testcase_32 | AC | 2 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,944 KB |
testcase_34 | AC | 2 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,940 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 384 ms
31,748 KB |
testcase_39 | AC | 864 ms
31,612 KB |
testcase_40 | AC | 261 ms
30,488 KB |
testcase_41 | AC | 639 ms
31,616 KB |
testcase_42 | AC | 626 ms
31,684 KB |
testcase_43 | AC | 596 ms
31,740 KB |
testcase_44 | AC | 647 ms
31,756 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define SPEED cin.tie(0);ios::sync_with_stdio(false); template<class Operator> class SegmentTree { Operator Op; using typeNode = decltype(Op.unitNode); size_t length; size_t num; vector<typeNode> node; vector<pair<size_t,size_t>> range; public: //unitで初期化 SegmentTree(const size_t num): num(num) { for (length = 1; length < num; length *= 2); node.resize(2 * length, Op.unitNode); range.resize(2 * length); for (int i = 0; i < length; ++i) range[i+length] = make_pair(i,i+1); for (int i = length - 1; i >= 0; --i) range[i] = make_pair(range[(i<<1)+0].first,range[(i<<1)+1].second); } //vectorで初期化 SegmentTree(const vector<typeNode> & vec) : num(vec.size()) { for (length = 1; length < vec.size(); length *= 2); node.resize(2 * length, Op.unitNode); for (int i = 0; i < vec.size(); ++i) node[i + length] = vec[i]; for (int i = length - 1; i >= 0; --i) node[i] = Op.funcNode(node[(i<<1)+0],node[(i<<1)+1]); range.resize(2 * length); for (int i = 0; i < length; ++i) range[i+length] = make_pair(i,i+1); for (int i = length - 1; i >= 0; --i) range[i] = make_pair(range[(i<<1)+0].first,range[(i<<1)+1].second); } //同じinitで初期化 SegmentTree(const size_t num, const typeNode init) : num(num) { for (length = 1; length < num; length *= 2); node.resize(2 * length, init); range.resize(2 * length); for (int i = 0; i < length; ++i) range[i+length] = make_pair(i,i+1); for (int i = length - 1; i >= 0; --i) range[i] = make_pair(range[(i<<1)+0].first,range[(i<<1)+1].second); } //[idx,idx+1) void update(size_t idx, const typeNode var) { if(idx < 0 || length <= idx) return; idx += length; node[idx] = Op.funcMerge(node[idx],var); while(idx >>= 1) node[idx] = Op.funcNode(node[(idx<<1)+0],node[(idx<<1)+1]); } //[l,r) typeNode get(int l, int r) { if (l < 0 || length <= l || r < 0 || length < r) return Op.unitNode; typeNode vl = Op.unitNode, vr = Op.unitNode; for(l += length, r += length; l < r; l >>=1, r >>=1) { if(l&1) vl = Op.funcNode(vl,node[l++]); if(r&1) vr = Op.funcNode(node[--r],vr); } return Op.funcNode(vl,vr); } //return [0,length] int PrefixBinarySearch(typeNode var) { if(!Op.funcCheck(node[1],var)) return num; typeNode ret = Op.unitNode; size_t idx = 2; for(; idx < 2*length; idx<<=1){ if(!Op.funcCheck(Op.funcNode(ret,node[idx]),var)) { ret = Op.funcNode(ret,node[idx]); idx++; } } return min((idx>>1) - length,num); } //range[l,r) return [l,r] int BinarySearch(size_t l, size_t r, typeNode var) { if (l < 0 || length <= l || r < 0 || length < r) return -1; typeNode ret = Op.unitNode; size_t off = l; for(size_t idx = l+length; idx < 2*length && off < r; ){ if(range[idx].second<=r && !Op.funcCheck(Op.funcNode(ret,node[idx]),var)) { ret = Op.funcNode(ret,node[idx]); off = range[idx++].second; if(!(idx&1)) idx >>= 1; } else{ idx <<=1; } } return off; } }; template<class typeNode> struct nodeGCDPointUpdate { typeNode unitNode = 0; typeNode funcNode(typeNode l,typeNode r){return ((r == 0) ? l : funcNode(r, l % r));} typeNode funcMerge(typeNode l,typeNode r){return r;} bool funcCheck(typeNode nodeVal,typeNode var){return var == nodeVal;} }; // solution by binary search in arbitary range on disjn sparse table int main() { SPEED ll N; cin >> N; vector<ll> A(N+1,1); for(int i = 0; i < N; ++i) cin >> A[i]; SegmentTree<nodeGCDPointUpdate<ll>> seg(A); ll ans=0; int r=1; for(int i=0; i<N; i++,r=max(r,i+1)){ while(r<=N){ if(seg.get(i, r)==1) break; r++; } ans+=N+1-r; } cout << ans << endl; }