Molly's Chemicals
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 DEBUGfreopen("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 DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}
Molly's Chemicals相关推荐
- C. Molly's Chemicals
题目链接:http://codeforces.com/problemset/problem/776/C C. Molly's Chemicals time limit per test 2.5 sec ...
- codeforces 776C Molly's Chemicals(连续子序列和为k的次方的个数)
题目链接 题意:给出一个有n个数的序列,还有一个k,问在这个序列中有多少个子序列使得sum[l, r] = k^0,1,2,3-- 思路:sum[l, r] = k ^ t, 前缀和sum[r] = ...
- 【codeforces 776C】Molly's Chemicals
[题目链接]:http://codeforces.com/contest/776/problem/C [题意] 让你找区间[i,j] 使得sum[i..j]=k^t,这里t=0,1,2,3.. -10 ...
- 有趣题目和认知合集(持续更新)
写写对一些算法的理解,挂几个有意思的题,可能也会挂几个板子题 算法理解偏向于能懂即可,没有严格的证明 快乐几何 [1.2]Volatile Kite 点到直线 快乐搜与暴力 [2.4]Short Co ...
- codeforces 776C
codeforces 776C 题目: C. Molly's Chemicals time limit per test2.5 seconds memory limit per test512 meg ...
- Codeforces 776B 776C 程序(夏洛克专场)
这里直接贴我的程序,题目和思路另翻博客 B. Sherlock and his girlfriend`// // main.cpp // journey // // Created by zhangd ...
- 专题记录1-前缀和差分
C - 前缀极差 2023HUEL寒假集训: 1.10 前缀和 - Virtual Judge (vjudge.net) #include <cstdio> #include <io ...
- AI得贤招聘官上线ChatGPT,免费为企业提供AI智能助手Molly
Molly是AI得贤招聘官基于"ChatGPT"的智能回答语言模型,她可以回答各种关于AI面试的问题,并帮助HR轻松解决撰写稿件.Molly不仅仅可以回答常见的问题,同时她还可以了 ...
- Toronto Research Chemicals 双(乙酰丙酮)铂(II)
艾美捷 Toronto Research Chemicals(TRC)双(乙酰丙酮)铂(II)用于肿瘤球体中铂族元素的定量生物成像. 艾美捷 Toronto Research Chemicals(T ...
最新文章
- MFC CTreeCtrl运用
- 各国家分析(马来西亚,秘鲁)
- SSH框架第一天——hibernate框架
- 从P560小型机B181201B故障代码识别手把手详解
- 图片热点的使用,html area 的用法
- 哨兵2号波段_分布式框架之高性能:Redis哨兵模式
- 正确使用日志的10个技巧(转)
- 使用Profile创建第一个Grails+Angular2应用
- mysql5.7 gtid问题_MySQL 5.7.5: 新语法WAIT_FOR_EXECUTED_GTID_SET 及存在的问题-阿里云开发者社区...
- 使用BeautifulSoup爬取“0daydown”网站的信息(1)
- PVE系列教程(三)、安装黑威联通
- 【Proteus仿真】基于STC15单片机简易数码管定时器时钟
- win7win8 64位汇编开发环境合集安装与设置
- PCM音频压缩A-Law算法,uLaw
- 【华为OD机试真题 Python】判断字符串子序列
- 计算机常见故障及排除方法,科学网—计算机常见故障和解决办法 - 李卓哲的博文...
- 百度网盘下载显示系统限制,无法下载解决
- sql 语句中 Sum(*) Nvl(name,0) Coun(*)的作用
- android平板忘了密码,平板电脑忘记密码怎么办
- 042-16 Backup and Recovery备份与恢复(前3种备份方式)
热门文章
- php抓取运动步数,使用PHP抓取微博数据
- 3000元电脑配置_2019年全新九代i59400F配RTX2060打游戏的装机电脑配置清单及价格...
- 笔记本电脑键盘切换_全球首款折叠屏笔记本电脑ThinkPad X1 Fold:5G高速互联拥抱PC场景融合时代...
- 北大计算机学院 教授 湖南人,北大湘籍教授邹恒甫简历
- 连接端口 配置hive_Zeppelin带有Kerberos认证的Hive解释器的配置
- 机器人简化图画手绘图_高通推出全新RB3 机器人平台,年内支持5G连接
- c#图片base64去转义字符_C#实现字符串与图片的Base64编码转换操作示例
- 图像处理opencv(一)
- Java web项目报错 Java compiler level does not match the version of the installed Java project facet.
- 清华大学高阳:Mastering Atari Games with Limited Data