题目大意:给出n个数(a1.....an),和一个数k,问有多少个区间的和等于k的幂 (1 ≤ n ≤ 10^5, 1 ≤ |k| ≤ 10, - 10^9 ≤ ai ≤ 10^9) 解题思路:首先,可以从题目得出k的幂最大不能超过n*ai=1e14.然后,我们先求出前缀和sum[1]...sum[n],k的i次幂为power[i].我们要求出一个区间和等于power[i]即sum[r]-sum[l]=power[i],转换一下sum[r]=sum[l]+power[i]. 所以我们只需要从1到…
题目链接 题意:给出一个有n个数的序列,还有一个k,问在这个序列中有多少个子序列使得sum[l, r] = k^0,1,2,3…… 思路:sum[l, r] = k ^ t, 前缀和sum[r] = sum[l-1] + k^t.即如果后面有一段序列使得sum[l,r] = k^t,那么它可以转化为前缀和相减使得这一段大小为k^t,即sum[i] = sum[j] + k^t (1 <= j < i). 那么对于处理好的每一个前缀和,直接往后面加上k^t(0<=t<=x,k^x是不…
链接:CodeForces - 776C 题意:给出数组 a[n] ,问有多少个区间和等于 k^x(x >= 0). 题解:求前缀和,标记每个和的个数.对每一个数都遍历到1e5,记录到答案. #include <bits/stdc++.h> using namespace std; long long n, k; map<long long, long long> mp; int main() { scanf("%lld%lld", &n, &am…
题目链接:http://codeforces.com/problemset/problem/776/C C. Molly's Chemicals time limit per test 2.5 seconds memory limit per test 512 megabytes input standard input output standard output Molly Hooper has n different kinds of chemicals arranged in a lin…
C. Molly's Chemicals time limit per test 2.5 seconds memory limit per test 512 megabytes input standard input output standard output Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The…
CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally ac…
[JZOJ5280]膜法师题解--思维+前缀和 题目链接 暴 力 过 于…
http://codeforces.com/problemset/problem/776/C 题意:给出一个有n个数的序列,还有一个k,问在这个序列中有多少个子序列使得sum[l, r] = k^0,1,2,3…… 思路:sum[l, r] = k ^ t, 前缀和sum[r] = sum[l-1] + k^t.即如果后面有一段序列使得sum[l,r] = k^t,那么它可以转化为前缀和相减使得这一段大小为k^t,即sum[i] = sum[j] + k^t (1 <= j < i). 那么对…
[题目链接]:http://codeforces.com/contest/776/problem/C [题意] 让你找区间[i,j] 使得sum[i..j]=k^t,这里t=0,1,2,3.. -10<=k<=10 求出区间个数; [题解] /* k^0==1 要求选[l,r] sum[l..r]==k^t,t>=0,t=1,2,3... 前缀和 pre[i]-pre[j] =k^t; j∈[1..i-1] pre[i]=k^t+pre[j-1]; 把dic[k^t+pre[j-1]]+…
处理出前缀和,枚举k的幂,然后从前往后枚举,把前面的前缀和都塞进map,可以方便的查询对于某个右端点,有多少个左端点满足该段区间的和为待查询的值. #include<cstdio> #include<map> using namespace std; typedef long long ll; map<ll,int>cnts; int n,m,e; ll a[100010],ans; ll b[1001]; int main() { // freopen("c…