結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
ゆきのん
|
| 提出日時 | 2020-04-25 00:03:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,766 bytes |
| コンパイル時間 | 2,415 ms |
| コンパイル使用メモリ | 173,516 KB |
| 実行使用メモリ | 94,464 KB |
| 最終ジャッジ日時 | 2024-11-07 21:01:00 |
| 合計ジャッジ時間 | 30,414 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 TLE * 3 -- * 1 |
ソースコード
#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 + 1;
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;
}
ゆきのん