-
Notifications
You must be signed in to change notification settings - Fork 0
/
776C.cpp
133 lines (61 loc) · 1.17 KB
/
776C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define endl "\n"
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll n,k,ans=0;
cin>>n>>k;
vector<ll> a(n),b(n+1);
for(int i=0;i<n;i++)
{
cin>>a[i];
}
b[0]=0;
for(int i=1;i<=n;i++)
{
b[i]=b[i-1]+a[i-1];
}
map<ll,ll> m;
if(k==1)
{
for(int i=n;i>=0;i--)
{
ans+=m[b[i]+1];
m[b[i]]++;
}
}
else if(k==-1)
{
for(int i=n;i>=0;i--)
{
ans+=m[b[i]+1];
ans+=m[b[i]-1];
m[b[i]]++;
}
}
else
{
ll cur=1;
for(int i=n;i>=0;i--)
{
cur=1;
while(cur<1e15)
{
ans+=m[b[i]+cur];
cur*=k;
}
m[b[i]]++;
}
}
cout<<ans;
return 0;
}