Meaningful Mean
a has N(N+1)⁄2 non-empty contiguous subsequences, {al,al+1,…,ar} (1≤l≤r≤N). Among them, how many have an arithmetic mean that is greater than or equal to K?
Constraints
All input values are integers.
1≤N≤2×105
1≤K≤109
1≤ai≤109
输入
N K
a1
a2
:
aN
输出
样例输入
3 6
7
5
7
样例输出
5
提示
All the non-empty contiguous subsequences of a are listed below:
{a1} = {7}
{a1,a2} = {7,5}
{a1,a2,a3} = {7,5,7}
{a2} = {5}
{a2,a3} = {5,7}
{a3} = {7}
Their means are 7, 6, 19⁄3, 5, 6 and 7, respectively, and five among them are 6 or greater. Note that {a1} and {a3} are indistinguishable by the values of their elements, but we count them individually.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct poi{ll sum,pos;}a[200010];
ll n,k,ans,cnt,tree[200010],lisan[200010];
void read(ll &k)
{
k=0;int f=1;char c=getchar();
while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
k*=f;
}
bool cmp(poi a,poi b){return a.sum<b.sum;}
int lowbit(int x){return x&-x;}
void add(int x,int delta)
{
for(int i=x;i<=cnt;i+=lowbit(i))
tree[i]+=delta;
}
int sum(int x)
{
int s=0;
for(int i=x;i>=1;i-=lowbit(i))
s+=tree[i];
return s;
}
int main()
{
read(n);read(k);
for(int i=1;i<=n;i++)read(a[i].sum),a[i].sum-=k;
for(int i=1;i<=n;i++)a[i].sum+=a[i-1].sum,a[i].pos=i;
sort(a,a+1+n,cmp);
for(int i=0;i<=n;i++)
{
if(a[i].sum!=a[i-1].sum||i==0)cnt++;
lisan[a[i].pos]=cnt;
}
for(int i=n;i>=0;i--)
{
ans+=sum(cnt)-sum(lisan[i]-1);
add(lisan[i],1);
}
printf("%lld\n",ans);
}
Meaningful Mean的更多相关文章
- clean code meaningful names
---恢复内容开始--- Meaningful Names: use Intention-Revealing Names //nice,Everyone who reads your code (in ...
- 有意义的命名 Meaningful names
名副其实 use intention-revealing names 变量.函数或类的名称应该已经答复了所有的大问题.它该告诉你,他为什么会存在,他做什么事,应该怎么用.我们应该选择都是致命了计量对象 ...
- Clean Code – Chapter 2: Meaningful Names
Use Intention-Revealing Names The name should tell you why it exists, what it does, and how it is us ...
- The Info-Button Standard: Bring Meaningful Use To the Patient
http://thehealthcareblog.com/blog/2010/01/28/the-info-button-standard-bringing-meaningful-use-to-the ...
- 英语阅读——A meaningful life
这篇文章是<新视野大学英语>第四册的第八单元的文章. 1 The death of an angel of animal rights activism(活动家) does not rat ...
- Meaningful Use 中与HL7相关的消息及医疗文档
汇总 HL7 消息 入出转消息 ADT A01,A03,A04,A08 免疫消息 VXU V04 电子处方消息 NEWRX Message v8.1 EDIFACT, v8.1 XML, v10.6 ...
- Why Creating a Meaningful Morning Routine Will Make You More Successful
https://medium.com/life-learning/how-creating-a-meaningful-morning-routine-will-make-you-more-succes ...
- [AngularJS] Transforming raw JSON data to meaningful output in AngularJS
angular.module('APP', []) .controller('MainController', function($scope, UserConstants){ var user = ...
- AtCoder Regular Contest 075 E - Meaningful Mean(树状数组)
题目大意:求一个数组中,平均值不小于k的连续子序列个数 所有数减去k,算个前缀和出来,就变成二维数点问题了. 没有修改,离线的话就是CZL所说的“NOIP最喜欢的套路”了:倒着加进BIT,以权值为数组 ...
- ARC075 E.Meaningful Mean(树状数组)
题目大意:给定n和k,问an中有多少子区间的平均值大于等于k 很巧妙的一个式子,就是如果一个区间[l, r]满足条件 那么则有 sum[r] - sum[l-1] >= (r-l+1)*k 整理 ...
随机推荐
- Halcon - 数据类型
这里给大家分享 Halcon 的数据类型结构图,方便初学者认知 Halcon 图1 Halcon Datatype
- public,protect,private访问权限
第一:private, public, protected 访问标号的访问范围. private:只能由1.该类中的函数.2.其友元函数访问.不能被任何其他访问,该类的对象也不能访问. protect ...
- SQL Server 截取两个固定字符之间的字符串(案例)
网上的问题: 参考这篇<函数PARSENAME使用和截取字符串>https://www.cnblogs.com/insus/p/10958452.html 的方法: )='||MO21|T ...
- Vue实现一个MarkDown编辑器
Vue实现一个markdown编辑器 前段时间做项目的时候,需要一个Markdown编辑器,在网上找了一些开源的实现,但是都不满足需求 说实话,这些开源项目也很难满足需求公司项目的需求,与其实现一个大 ...
- MATLAB---make与makefile简单介绍
1 make.makefile概述 makefile定义了一系列的规则,来规定哪些部分先编译,哪些部分后编译,写好makefile以后,只需一个make命令就可以让整个工程完全自动编译,所以简单的说, ...
- Windows下安装CUDA8.0
在Win10下安装CUDA8.0,并使用VS2013测试: 机器配置: Windows 10 VS 2013 CUDA8.0 CUDA 8.0:下载地址 CUDA其他版本:下载地址 1. 安装CUDA ...
- 洛谷P3608 [USACO17JAN]Balanced Photo平衡的照片
P3608 [USACO17JAN]Balanced Photo平衡的照片 题目描述 Farmer John is arranging his NN cows in a line to take a ...
- Google Analytics & Webtrend 使用笔记
GA和webtrend中的参数,每每遇到了都记不住.遇到一点记一点好了... Page Views(PV): 浏览次数.用户每打开一个页面,记录为1个PV:用户多次打开同一个页面,PV累计多次. Da ...
- 前端三部曲之Html -- 1(html的基本结构和常见的meta标签的作用)
一个H5页面的基本结构是什么 我么在编辑器中输入html:5可以得到 <!DOCTYPE html> <!-- 声明文档类型 --> <html lang="e ...
- base64编码后的pdf文件前端页面展示--pdf.js的应用
最近在整理项目中用到的插件或者使用心得,感觉还是写成博客,能加深新一层的理解. 我先说一下我的需求:由于java后台编译的文件流在手机端加载速度太慢,所以想着可以在前端解析,放在页面展示给用户. 所以 ...