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 ...
随机推荐
- SQLServer的学习场景(关于row_number()和COALESCE()的使用)
--使用Sql语句,统计出每辆汽车每天行驶的里程数(不是总里程) 以下为脚本 CREATE TABLE [dbo].[CarData]([CarID] [int] NULL,[Mileage] [in ...
- HDU 1394 Minimum Inversion Number(最小逆序数 线段树)
Minimum Inversion Number [题目链接]Minimum Inversion Number [题目类型]最小逆序数 线段树 &题意: 求一个数列经过n次变换得到的数列其中的 ...
- Redis内存使用优化与存储
抄自http://www.infoq.com/cn/articles/tq-redis-memory-usage-optimization-storage 本文将对Redis的常见数据类型的使用场景以 ...
- JVM实用参数(八)GC日志
本系列的最后一部分是有关垃圾收集(GC)日志的JVM参数.GC日志是一个很重要的工具,它准确记录了每一次的GC的执行时间和执行结果,通过分析GC日志可以优化堆设置和GC设置,或者改进应用程序的对象分配 ...
- dubbo工作原理
part -- 外挂1.dubbo借助spring的schema启动和初始化 1.1 spring扫描所有jar下META-INF的spring.handlers和spring.schemas. 1. ...
- oleDB 导入excel遇到的问题
本地测试一切ok. 到服务器上测试各种报错,先装了office2010,又装了AccessDatabaseEngine,之后报"Microsoft Excel 不能访问文件 可能的原因有: ...
- jQuery MiniUI开发系列之:安装部署
jQuery MiniUI是一套纯Javascript的WebUI控件库,它由几十个Javascript控件组成,是不依赖服务端和数据库的. 下载jQuery MiniUI,解压缩后,开发者可以直接在 ...
- JAVA Socket 编程学习笔记(一)
1. Socket 通信简介及模型 Java Socket 可实现客户端--服务器间的双向实时通信.java.net包中定义的两个类socket和ServerSocket,分别用来实现双向连接的cli ...
- 【SSM 5】Mybatis分页插件的使用
一.添加maven依赖项 <span style="font-family:KaiTi_GB2312;font-size:18px;"><dependency&g ...
- oracle-关于dual
来源:百度知道1. dual 是一张表.是一张只有一个字段,一行记录的表. 2.习惯上,我们称之为'伪表'.因为他不存储主题数据.3. 他的存在,是为了操作上的方便.因为select 都是要有特定对象 ...