【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
处理出前缀和,枚举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.in","r",stdin);
scanf("%d%d",&n,&m);
if(m==0 || m==1)
b[++e]=m;
else if(m==-1)
{
b[++e]=m;
b[++e]=-m;
}
else
{
ll now=1ll;
while(now<=100000000000000ll && now>=-100000000000000ll)
{
b[++e]=now;
now*=(ll)m;
}
}
for(int i=1;i<=n;++i)
scanf("%I64d",&a[i]);
for(int i=2;i<=n;++i)
a[i]+=a[i-1];
++cnts[0];
for(int i=1;i<=n;++i)
{
for(int j=1;j<=e;++j)
ans+=cnts[a[i]-b[j]];
++cnts[a[i]];
}
printf("%I64d\n",ans);
return 0;
}
【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals的更多相关文章
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀
A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几 ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
感觉自己做有关区间的题目方面的思维异常的差...有时简单题都搞半天还完全没思路,,然后别人提示下立马就明白了...=_= 题意:给一个含有n个元素的数组和k,问存在多少个区间的和值为k的次方数. 题解 ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT
题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds m ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an aff ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) B
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her s ...
- 【2-SAT】【并查集】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem
再来回顾一下2-SAT,把每个点拆点为是和非两个点,如果a能一定推出非b,则a->非b,其他情况同理. 然后跑强连通分量分解,保证a和非a不在同一个分量里面. 这题由于你建完图发现都是双向边,所 ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D
Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlo ...
随机推荐
- [hdu 4417]树状数组+离散化+离线处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 把数字离散化,一个查询拆成两个查询,每次查询一个前缀的和.主要问题是这个数组是静态的,如果带修改 ...
- bzoj4589 FWT xor版本
4589: Hard Nim Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 865 Solved: 484[Submit][Status][Disc ...
- npm安装node-sass失败,EACCES: permission denied
增加--unsafe-perm,即 sudo npm install node-sass --unsafe-perm --save-dev 成功安装node-sass
- NET面试题 (四)
1, 面向对象的思想主要包括什么? 封装.继承.多态. TLW: 封装:用抽象的数据类型将数据和基于数据的操作封装在一起,数据被保护在抽象数据类型内部. 继承:子类拥有父类的所有数据和操作. 多态:一 ...
- HDU2546饭卡---(DP 经典背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2546 饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory L ...
- CVE-2016-6662 mysql RCE测试
参考:http://bobao.360.cn/learning/detail/3027.html ,我尝试第一种方法 1.先修改mysql_hookandroot_lib.c里面的反弹地址和端口: # ...
- linux中链表的使用【转】
转自:http://blog.csdn.net/finewind/article/details/8074990 Linux下链表的使用方法跟我们常规的不一样,通常情况下,链表的next指针都指向节点 ...
- Flex slider参数详细
$(window).load(function() { $('.flexslider').flexslider({ animation: "fade", //String: Sel ...
- 使用bottle进行web开发(9):文件上传;json传递
1.文件上传 如果要完成文件上传,则需要对上文的form做一点改动,具体如下: <form action="/upload" method="post" ...
- xshell连接虚拟机CentOS出现eth0 device not found的解决方法
昨天用xshell连接虚拟机上的centOS老是连接不上,ifconfig eth0 命令显示 device not found.不知道是什么原因... 折腾了好久 网上是各种搜啊 终于找到解决方法了 ...