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 ...
随机推荐
- UICollectionView的使用小记录和一些说明
// // MallTestViewController.h // fitmiss // // Created by bill on 16/6/28. // Copyright © 2016年 lea ...
- 重置mysql数据库密码
# /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # my ...
- Stream 同步错误之解决方案 ORA-00001 ORA-26787 ORA-26786
stream是 oracle 11g 支持的数据同步技术, 虽然该技术已经不是什么新技术, 但目前国内采用该技术开发的软件不多见. stream 同步软件项目参与近一年, 近期软件上线实施, 效果不 ...
- 图片Exif 信息中Orientation的理解和对此的处理
这个问题是在用七牛上传图片后获取宽高时发现的,一张图片,用图片浏览器打开始终是竖图,但是查看属性或者用七牛获取宽高,却发现宽大于高,也就是在属性中这是个横图.这样导致客户端用该宽高来展示图片会出现问题 ...
- (C++) System return error codes.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681385(v=vs.85).aspx
- url-pattern
一,servlet容器对url的匹配过程: 当 一个请求发送到servlet容器的时候,容器先会将请求的url减去当前应用上下文的路径作为servlet的映射url,比如我访问的是 http://lo ...
- sharedPreferences的用法
做软件开发应该都知道,很多软件会有配置文件,里面存放这程序运行当中的各个属性值,由于其配置信息并不多,如果采用数据库来存放并不划算,因为数据库连 接跟操作等耗时大大影响了程序的效率,因此我们使用键值这 ...
- G不可失
html和css部分和引用的库 <!DOCTYPE html><html lang="en"><head> <meta charset=& ...
- Java项目往数据库中插入数据,出现中文乱码
项目环境: JSP+Servlet+Mysql数据库 需要检查的地方: 1. java项目整体的编码格式为utf-8.并且将数据传递给数据库之前,数据是否依旧是正常的(可以通过打断点的方式一步步跟踪查 ...
- Linux下的shell编程(二)BY 四喜三顺
Ctrl + Alt + T 打开终端, $代表普通用户,#代表超级用户(root user)如: xiangqi@xiangqi ~$ root@xiangqi ~# ec ...