http://codeforces.com/problemset/problem/776/C

题意:给出n个数,和一个数k,现在问你有多少个区间和等于k的x次方,x从0到无穷

C++版本一

题解:先求出前缀和,也就是求有多少个sum[r]-sum[l]=pow(k,x),r>l。x最大只有lg(1e14),可以将式子变为sum[r]-pow(k,x)=sum[l]。每次结束后将前缀和放到map里

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const ll INF = 0x3f3f3f3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
ll ans,cnt,flag,temp;
ll sum[N];
set<ll>a;
map<ll,int>st;
char str;
struct node{};
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    //scanf("%d",&t);
    //while(t--){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%I64d",&sum[i]),sum[i]+=sum[i-1];
    a.insert(1);
    temp=k;
    while(temp<INF&&cnt<60){
        a.insert(temp);
        cnt++;
        temp*=k;
    }
    st[0]=1;
    for(int i=1;i<=n;i++){
        for(set<ll>::iterator it=a.begin();it!=a.end();it++)ans+=st[sum[i]-*it];
        st[sum[i]]++;
    }
    cout<<ans<<endl;
    //}

#ifdef DEBUG
	printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Hello world!" << endl;
    return 0;
}