XidianOJ 1099 A simple problem
题目描述
一个长度为N的数组A, 所有数都是整数 ,0 <= A[i] <= 1000000,1 <= i <= N,1 <= N <= 100000,对于 任意i,j ,1 <= i <= j <= N,[i, j]中所有数为原数组的一个子区间, 现在要求子区间的和小于等于K的子区间有多少个, 0 <= K <= 10000。
虽然xry111很SB,但还是在O(N)的时间复杂度内就做出了这题,你呢?
输入
第一行整数T 代表数据组数,1 <= T <= 12
每组数据第一行 整数 N, K。
接下来一行N个整数, 由空格隔开。
输出
输出子区间的和小于等于K的子区间的个数。 每组输出占一行。
--正文
明明是简单的题,却做了半天。。。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
long long a[];
int n,k,i,j;
int main(){
int time,T; scanf("%d",&T);
for (time=;time<=T;time++){
int now = ;
LL sum = ,res = ;
scanf("%d %d",&n,&k);
for (i=;i<=n;i++){
scanf("%lld",&a[i]);
sum += a[i];
if (sum <= k) {
res += i - now + ;
}
else {
while (sum > k){
sum = sum - a[now]; now ++;
}
res += i - now + ;
}
}
printf("%lld\n",res);
}
return ;
}
XidianOJ 1099 A simple problem的更多相关文章
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- POJ 3468 A Simple Problem with Integers(线段树/区间更新)
题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Description Yo ...
- poj 3468:A Simple Problem with Integers(线段树,区间修改求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 58269 ...
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
- poj3468 A Simple Problem with Integers (线段树区间最大值)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92127 ...
- POJ3648 A Simple Problem with Integers(线段树之成段更新。入门题)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53169 Acc ...
- BZOJ-3212 Pku3468 A Simple Problem with Integers 裸线段树区间维护查询
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1278 Sol ...
- POJ 3468 A Simple Problem with Integers(线段树区间更新区间查询)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92632 ...
- A Simple Problem with Integers(树状数组HDU4267)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
随机推荐
- hibernate:Named query not known: findXXXX or XXXX is not mapped
.hbm.xml文件所放的位置怎么看怎么都在spring配置的扫描路径中,就是会出现标题所示错误,查看log日志,的确也没发现XXXX被mapped的记录~ 参考解决方案: 在eclipse导出jar ...
- logstash无法使用conf启动
最近刚开始学习使用logstash,再安装好后准备验证下第一个demo的时候,出现了问题 Error: Expected one of #, input, filter, output at line ...
- js对中文编码 防止乱码
//编码 encodeURI(encodeURI(lm.getValueByName("name"))) 解码 decodeURI(date)
- 常见的HTTP返回码如4xx, 5xx
常见的HTTP返回码如4xx, 5xx Client Error =====================400 Bad Request 因为错误的语法导致服务器无法理解请求信息.401 Unaut ...
- 【maven】之配置开发,测试,正式环境pom.xml文件
在进行web程序开发,如果项目组没有使用自动化发布工具(jenkins + maven + svn + tomcat ),我们一般会使用maven的热部署来完成发布,在部署的过程中我们开发,测试,生产 ...
- HTML5常用的方法
1.html禁止手机页面放大缩小 在页面head中加入<meta name="viewport" content="width=device-width, init ...
- 【学】React的学习之旅7-官方例子总结
如果在标签里有注释,除了使用/**/之外,如果写在子标签中,外面还需要用{}包起来,指明这段是javascript代码,否则这段注释会直接显示在页面上,例如 render:function (){ r ...
- flash flex 程序出现错误 Error #2032
解决思路参考: http://www.cnblogs.com/enjoyprogram/archive/2012/06/21/2557615.html 有可能是这种情况: 状况:在安装flshbuil ...
- [Linux] 关于Centos6中ulimit nproc用户进程数的限制
一.缘由: 在启动mongodb的时候,有Warning提示soft rlimits too low,就是用户使用进程数过小,遂调高系统资源关于用户最大进程数的限制ulimit -u. 先暂时使设置生 ...
- 转 makefile
转自http://blog.chinaunix.net/uid-21411227-id-1826747.html gcc是gnu旗舰产品,目前基本上就是和unix捆绑在一起分发的.这个东西功能强大,但 ...