【枚举】【前缀和】【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 ...
随机推荐
- innodb log file与binlog的区别在哪里?
Q: innodb log file与binlog的区别在哪里?有人说1.mysql的innodb引擎实际上是包装了inno base存储引擎.而innodb log file是由 inno base ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B
B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- [lucene系列笔记3]用socket把lucene做成一个web服务
上一篇介绍了用lucene建立索引和搜索,但是那些都只是在本机上运行的,如果希望在服务器上做成web服务该怎么办呢? 一个有效的方法就是用socket通信,这样可以实现后端与前端的独立,也就是不管前端 ...
- HDU2255:奔小康赚大钱(KM算法)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- java注解(Annotation)的简单介绍
注解你可以理解为一个特殊的类,或者接口其自定义个格式形如 public @interface 注解名(){ //注解的属性,特别提醒当注解的属性为value时,在对其赋值时,可以不写value,而直接 ...
- c++(类)构造函数、复制构造函数
复制构造函数是一种特殊的构造函数,它的作用是用一个已经存在的对象去初始化另一个对象.一般情况下不需要自行定义复制构造函数,系统默认提供一个逐个复制成员值的复制构造函数. 何时要使用呢? 1.将新对象初 ...
- SpringMVC学习 -- REST
REST:表现层状态转化. REST 是目前最流行的一种互联网软件架构.他结构清晰.符合标准.易于理解.扩展方便 , 所以正得到越来越多网站的采用. 状态转化:浏览器 form 表单只支持 GET 和 ...
- 【BZOJ1419】 Red is good [期望DP]
Red is good Time Limit: 10 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description 桌面上有R张红牌和B张 ...
- noip2014 提高组
T1 生活大爆炸版 石头剪刀布 题目传送门 就是道模拟题咯 #include<algorithm> #include<cstdio> #include<cstring&g ...
- Codeforces Round #301 解题报告
感觉这次的题目顺序很不合理啊... A. Combination Lock Scrooge McDuck keeps his most treasured savings in a home sa ...