求条,pls
#include<iostream>
#include<map>
#include<algorithm>
#define int long long
using namespace std;
int n,m;
int lgm[200002];
int st[200002][20];
map<int,int>ans;
int q(int l,int r){
int p=lgm[r-l+1];
return max(st[l][p],st[r-(1<<p)+1][p]);
}
int upbound(int res,int s,int l){
int r=n+1;
while(l<r){
int mid=(l+r)/2;
if(q(s,mid)<res) r=mid;
else l=mid+1;
}
return l;
}
void get(int s){
int cr=st[s][0];
int lb=s;
int ub;
while(1){
ub=upbound(cr,s,lb);
ans[cr]+=ub-lb;
if(ub>n) return;
cr=q(s,ub);
lb=ub;
}
}
signed main(){
cin>>n;
for(int l=2;l<=n;l++){
lgm[l]=lgm[l/2]+1;
}
for(int i=1;i<=n;i++){
cin>>st[i][0];
}
for(int p=1;(1<<p)<=n;p++){
for(int l=1;l+(1<<p)-1<=n;l++){
st[l][p]=__gcd(st[l][p-1],st[l+(1<<(p-1))][p-1]);
}
}
for(int i=1;i<=n;i++) get(i);
cin>>m;
while(m--){
int x;
cin>>x;
cout<<ans[x]<<endl;
}
return 0;
}
如果马蜂傻逼,请见谅(