結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2020-04-24 21:53:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,562 ms / 2,000 ms |
| コード長 | 1,489 bytes |
| コンパイル時間 | 2,791 ms |
| コンパイル使用メモリ | 210,920 KB |
| 最終ジャッジ日時 | 2025-01-09 23:36:43 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int ARC023_D()’:
main.cpp:41:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:43:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | for(int i=0;i<n;i++) scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
template<typename T>
struct SparseTable{
using F = function<T(T, T)>;
vector< vector<T> > dat;
vector<int> ht;
const F f;
SparseTable(){}
SparseTable(F f):f(f){}
void build(const vector<T> &v){
int n=v.size(),h=1;
while((1<<h)<=n) h++;
dat.assign(h,vector<T>(n));
ht.assign(n+1,0);
for(int j=2;j<=n;j++) ht[j]=ht[j>>1]+1;
for(int j=0;j<n;j++) dat[0][j]=v[j];
for(int i=1,p=1;i<h;i++,p<<=1)
for(int j=0;j<n;j++)
dat[i][j]=f(dat[i-1][j],dat[i-1][min(j+p,n-1)]);
};
T query(int a,int b){
int l=b-a;
return f(dat[ht[l]][a],dat[ht[l]][b-(1<<ht[l])]);
}
};
//END CUT HERE
#ifndef call_from_test
signed ARC023_D(){
using ll = long long;
int n;
scanf("%d",&n);
vector<ll> a(n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
auto f=[](ll a,ll b){return gcd(a,b);};
SparseTable<ll> st(f);
st.build(a);
map<ll, ll> ans;
for(int i=0;i<n;i++){
int l=i;
ll pre=a[i],lst=st.query(i,n);
while(lst!=pre){
int r=n,pl=l;
while(l+1<r){
int m=(l+r)>>1;
if(st.query(i,m)!=pre) r=m;
else l=m;
}
ans[pre]+=l-pl;
pre=st.query(i,r);
}
ans[lst]+=n-l;
}
printf("%lld\n",ans[1]);
return 0;
}
/*
verified on 2019/11/11
https://atcoder.jp/contests/arc023/tasks/arc023_4
*/
signed main(){
ARC023_D();
return 0;
}
#endif
beet