题目描述

一个长度为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的更多相关文章

  1. POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  2. POJ 3468 A Simple Problem with Integers(线段树/区间更新)

    题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS     Memory Limit: 131072K Description Yo ...

  3. poj 3468:A Simple Problem with Integers(线段树,区间修改求和)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 58269   ...

  4. ACM: A Simple Problem with Integers 解题报告-线段树

    A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...

  5. poj3468 A Simple Problem with Integers (线段树区间最大值)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92127   ...

  6. POJ3648 A Simple Problem with Integers(线段树之成段更新。入门题)

    A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53169 Acc ...

  7. 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 ...

  8. POJ 3468 A Simple Problem with Integers(线段树区间更新区间查询)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92632   ...

  9. A Simple Problem with Integers(树状数组HDU4267)

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...

随机推荐

  1. 服务端性能测试校准v1.2

    服务端性能测试工具校验v1.2 想知道压力工具实际并发多少,想知道压力工具统计响应数据准不准,来试试这款校准工具. 更新说明: 1.修正总接收请求显示上限. 2.随着响应时间增加,自动增加处理线程. ...

  2. [Linux] 无法访问国外网站,完成epel源安装的解决办法--待续

    一.缘由: 由于一个机房的网络限制,无法访问国外IP地址,在安装一些开源软件的时候比如smokeping.ansible就无法从epel源在线安装, 编译安装的话,又需要安装各种依赖,麻烦的一逼.所以 ...

  3. sersync

    一.准备 1.目标:从192.168.0.1上把/app/web/cnblogs.com/data下文件同步到192.168.0.2下的/app/web/cnblogs-slave.com/data: ...

  4. ubuntu下编译protobuf

    参考: http://blog.csdn.net/wuzuyu365/article/details/51900676 1.下载protobuf下载地址:https://github.com/goog ...

  5. Django进阶篇(二)

    中间件 解析 django 中的中间件(middleware),在django中,中间件其实就是一个类,在请求到来和结束后, django会根据自己的规则在合适的时机执行中间件中相应的方法. 在dja ...

  6. 在Web中使用Windows控件

    版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+] 将Net控件转化为ActiveX控件 1GUID 2实现IObjectSafety接口 3程序集设定 制作安装程序 Web集 ...

  7. [POJ2151]Check the difficulty of problems (概率dp)

    题目链接:http://poj.org/problem?id=2151 题目大意:有M个题目,T支队伍,第i个队伍做出第j个题目的概率为Pij,问每个队伍都至少做出1个题并且至少有一个队伍做出N题的概 ...

  8. iOS8下bundle路径变更

    iOS8下路径变为: /Users/username/Library/Developer/CoreSimulator/Devices/786824FF-6D4C-4D73-884A-696514481 ...

  9. 如何在winform或者wpf里面打开浏览器并设置宽高位置

    需要SHDocVw.dll 文件或AxSHDocVw.dll 文件,.net默认是没有的,先生产这两个文件,请在Visual Studio 命令提示符下运行下面的命令: aximp %WINDIR%\ ...

  10. sql2008r 收缩数据库日志log文件;删除errorlog文件的方法

    1.清空log文件,以减少数据库文件log所占的空间 USE dbname1 ; GO ALTER DATABASE dbname1 SET RECOVERY SIMPLE;--设置简单恢复模式 GO ...