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 ...
随机推荐
- TextBlock
一.TextBlock与Lable TextBlock是比Lable更底层的控件如果用TextBlock可以完成的需求就尽量不用Lable可以稍微提升一点性能. 参考文档 二.TextBlock内容过 ...
- 使用ionic framework创建一个简单的APP
ionic是一个以cordova为基础的html5前端框架,功能强大,能够快速做出与原生开发相似的应用. 一,安装和配置 1,安装(前提:cordova环境配置完成) npm install -g i ...
- 【zz】MIT牛人解说数学体系
作者:林达华 一.为什么要深入数学的世界 作为计算机的学生,我(原作者)没有任何企图要成为一个数学家.我学习数学的目 的,是要想爬上巨人的肩膀,希望站在更高的高度,能把我自己研究的东西看得更深广一些. ...
- 【总结】JS里的数组排序
虽然贴了2种办法,但是思路是一致的,都是先从数组里找出最小值,一种是找到一个放进新数组: 另一种是找到后和第i个数交换,i每次自增 主要用到2个函数: 从一个数组里找出最小值: 两个元素互换位置 fu ...
- 彻底弄懂响应式设计中的em和rem
前一阵子在响应式开发中遇到了em和rem的问题,也上网搜过一些文章,篇幅很长,也没有仔细看,今天来总结一下. rem是指:根元素(root element,html)的字体大小, em是指:父元素的字 ...
- Sql Server分割字符串函数
-- Description: 分割字符串函数 -- SELECT * FROM dbo.Split('a,b,c,d,e,f,g',',') -- ========================= ...
- asp.net mvc多条件+分页查询解决方案
开发环境vs2010 css:bootstrap js:jquery bootstrap paginator 原先只是想做个mvc的分页,但是一般的数据展现都需要检索条件,而且是多个条件,所以就变成了 ...
- [ActionScript 3.0] 获取随机颜色
import flash.display.MovieClip; import flash.geom.ColorTransform; //方法一 var red:Number = Math.random ...
- Convert Excel data to MDB file
所需组件: microsoft ado ext. 2.8 for ddl and security 或者更新的组件. 添加: using ADOX;using System.Runtime.Inter ...
- sqlserver 2008 建立订阅发布时 报错 解决方案 “错误 2812” 无法创建存储过程
11月10日早上 一大早,还在地铁14号线上 ,接到同事给的信息 说我们的XX系统宕机了,本想没什么问题,一般服务器 只要硬件没有问题 重启一下就可以了, 但是事与愿违,偏偏最后检测到服务器磁盘阵列 ...