题目:
题意:
分析:
看到每个数最大只能是
1
e
8
1e8
1e8,最多有
2
e
5
2e5
2e5个数,而
k
k
k最大是
1
e
5
1e5
1e5,所以我们的乘积最大也只能到
2
e
18
2e18
2e18
所以除了
1
1
1,我们最多只会算
l
o
g
log
log个数,所以考虑把相邻的
1
1
1缩成一个数,其他的数暴力算
代码:
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cmath>
#define LL long long
using namespace std;
inline LL read() {
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1; s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0'; s=getchar();}
return d*f;
}
LL a[200005],s[200005],len=0;
int main()
{
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
LL n=read(),k=read();
for(LL i=1;i<=n;i++)
{
a[++len]=read();
if(a[len]==1) s[len]=1;
if(a[len]==1&&a[len-1]==1) s[--len]++;
}
LL lim=ceil(log2(n));
LL ans=0;
for(LL l=1;l<=len;l++)
{
if(a[l]!=1)
{
LL ss=0,sum=0,mul=1;
for(LL r=l;ss<=lim&&r<=len;r++)
{
if(a[r]==1)
{
if(!(mul%k))
{
LL p=mul/k;
if(p-sum<=s[r]&&p-sum>0) ans++;
}
sum+=s[r];
}
else
{
ss++;
if(2e18/mul<a[r]) break;
mul*=a[r];sum+=a[r];
if(sum*k==mul) ans++;
}
}
}
else
{
for(LL b=1;b<=s[l];b++)
{
LL ss=0,mul=1,sum=b;
if(k==1) ans++;
for(LL r=l+1;ss<=lim&&r<=len;r++)
{
if(a[r]==1)
{
if(!(mul%k))
{
LL p=mul/k;
if(p-sum<=s[r]&&p-sum>0) ans++;
}
sum+=s[r];
}
else
{
ss++;
if(2e18/mul<a[r]) break;
mul*=a[r];sum+=a[r];
if(sum*k==mul) ans++;
}
}
ss++;
}
}
}
cout<<ans;
return 0;
}