这题其实就是,区间长度为x的区间个数,然后我们枚举x就可以了……
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<queue>
#include<list>
#include<stack>
#include<bitset>
#include<cmath>
#include<map>
#include<functional>
#define int long long
#define IO ios::sync_with_stdio(false)
using namespace std;
int n,k,a[100005],ans,sum;
map<int,int>mp;
signed main()
{
IO;
cin>>n>>k;
mp[0]++;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
if(k==1)
{
ans+=mp[sum-1];
}
else if(k==-1)
{
ans+=mp[sum-1]+mp[sum+1];
}
else
{
int t=1;
while(abs(t)<=1e15)
{
ans+=mp[sum-t];
t*=k;
}
}
mp[sum]++;
}
cout<<ans;
}