結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | ゆきのん |
提出日時 | 2020-04-24 23:58:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,766 bytes |
コンパイル時間 | 1,575 ms |
コンパイル使用メモリ | 169,764 KB |
実行使用メモリ | 89,344 KB |
最終ジャッジ日時 | 2024-04-24 18:23:58 |
合計ジャッジ時間 | 30,478 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 566 ms
89,344 KB |
testcase_01 | AC | 468 ms
89,216 KB |
testcase_02 | AC | 596 ms
89,216 KB |
testcase_03 | AC | 132 ms
43,648 KB |
testcase_04 | AC | 244 ms
87,936 KB |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | AC | 198 ms
44,032 KB |
testcase_08 | AC | 173 ms
43,648 KB |
testcase_09 | AC | 575 ms
89,344 KB |
testcase_10 | AC | 541 ms
88,832 KB |
testcase_11 | AC | 591 ms
89,088 KB |
testcase_12 | AC | 548 ms
88,832 KB |
testcase_13 | AC | 809 ms
89,088 KB |
testcase_14 | AC | 807 ms
89,088 KB |
testcase_15 | AC | 773 ms
88,704 KB |
testcase_16 | AC | 762 ms
88,704 KB |
testcase_17 | AC | 792 ms
88,960 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | AC | 5 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | AC | 745 ms
88,704 KB |
testcase_23 | AC | 615 ms
87,808 KB |
testcase_24 | AC | 776 ms
88,960 KB |
testcase_25 | AC | 722 ms
88,576 KB |
testcase_26 | AC | 742 ms
88,576 KB |
testcase_27 | AC | 1 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 1 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 577 ms
89,216 KB |
testcase_39 | AC | 609 ms
89,216 KB |
testcase_40 | AC | 571 ms
88,064 KB |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
testcase_44 | TLE | - |
ソースコード
#include<bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair<LL,LL> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;} const LL mod=1000000007; const LL LINF=1LL<<62; const int INF=1<<30; int dx[]={1,0,-1,0,1,-1,1,-1}; int dy[]={0,1,0,-1,1,-1,-1,1}; template< typename T > struct SparseTable { vector< vector< T > > st; SparseTable() {} SparseTable(const vector< T > &v) { int b = 0; while((1 << b) <= v.size()) ++b; st.assign(b, vector< T >(1 << b)); for(int i = 0; i < v.size(); i++) { st[0][i] = v[i]; } for(int i = 1; i < b; i++) { for(int j = 0; j + (1 << i) <= (1 << b); j++) { st[i][j] = gcd(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]); } } } inline T rmq(int l, int r) // [l, r) { int b = 32 - __builtin_clz(r - l) - 1; return (gcd(st[b][l], st[b][r - (1 << b)])); } }; int main(){ int n;cin >> n; vector<LL> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } SparseTable<LL> st(a); LL ans = 0; for (int i = 0; i < n; i++) { int l = i, r = n + 2; while(abs(r - l) > 1) { int m = (r + l) / 2; if(st.rmq(i, m) != 1) l = m; else r = m; } ans += max(0, n - l); } cout << ans << endl; return 0; }