2015暑假多校联合---Assignment(优先队列)
First Sample, the satisfied groups include:[1,1]、[2,2]、[3,3]、[4,4] 、[2,3]
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
using namespace std;
int a[]; struct cmp1
{
bool operator()(const int a1,const int a2)
{
return a[a1]>a[a2];
}
};
struct cmp2
{
bool operator()(const int a1,const int a2)
{
return a[a1]<a[a2];
}
};
priority_queue<int,vector<int>,cmp1>q1;
priority_queue<int,vector<int>,cmp2>q2; int main()
{
int T;
int n,k;
cin>>T;
while(T--)
{
scanf("%d%d",&n,&k);
for(int i=; i<n; i++)
scanf("%d",&a[i]);
long long sum=;
int len1=,len2=;
for(int i=; i<n; i++)
{
q1.push(i);
q2.push(i);
len2=i;
endw:
int maxn=a[q2.top()];
int minn=a[q1.top()];
if(maxn-minn<k) sum+=len2-len1+;
else
{
if(q2.top()>q1.top())
{
len1=t+;
int t=q1.top();
while(q1.top()<=t)
q1.pop();
goto endw;
}
else
{
len1=t+;
int t=q2.top();
while(q2.top()<=t)
q2.pop();
goto endw;
}
}
}
while(!q1.empty())
q1.pop();
while(!q2.empty())
q2.pop();
printf("%lld\n",sum);
}
return ;
}
2015暑假多校联合---Assignment(优先队列)的更多相关文章
- 2015暑假多校联合---CRB and His Birthday(01背包)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5410 Problem Description Today is CRB's birthda ...
- 2015暑假多校联合---Expression(区间DP)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5396 Problem Description Teacher Mai has n numb ...
- 2015暑假多校联合---Zero Escape(变化的01背包)
题目链接 http://acm.hust.edu.cn/vjudge/contest/130883#problem/C Problem Description Zero Escape, is a vi ...
- 2015暑假多校联合---Mahjong tree(树上DP 、深搜)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5379 Problem Description Little sun is an artis ...
- 2015暑假多校联合---Cake(深搜)
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...
- 2015暑假多校联合---Friends(dfs枚举)
原题链接 Problem Description There are n people and m pairs of friends. For every pair of friends, they ...
- 2015暑假多校联合---Problem Killer(暴力)
原题链接 Problem Description You are a "Problem Killer", you want to solve many problems. Now ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
随机推荐
- Mybatis逆向工程构建项目实例.
2016/11/06更新: 因为有博友可能需要这份代码, 所以我就直接发到百度云上面和大家共享, 如果链接失效请大家留言提示即可.下载地址: http://pan.baidu.com/s/1i57E8 ...
- Atitti.数字证书体系cer pfx attilax总结
Atitti.数字证书体系cer pfx attilax总结 一.数字证书常见标准 1 数字证书文件格式(cer和pfx)的区别: 1 二.数字证书存储内容 2 X.509是一种非常通用的证书格式. ...
- 实例快速上手 -ASP.NET 4.5新特性WebAPI从入门到精通
在新出的MVC4中,增加了WebAPI,用于提供REST风格的WebService,新生成的WebAPI项目和典型的MVC项目一样,包含主要的Models.Views.Controllers等文件夹和 ...
- Searching for a valid kernel header path... The path "" is not a valid path to the ***** kernel headers. Would you like to change it? [yes]
在centos 6.5安装vmtools时候,解压包,mount挂载后,安装pl过程中报 这个问题,半天没有解决,google 后发现这样就行了 I installed the kernel-deve ...
- 第七节:Class与Style绑定
1.绑定class,v-bind:class 简写为::class 对象方式: <!-- 绑定一个class对象,也可以绑定data中的对象--> <span v-bind:cla ...
- 解析.NET 许可证编译器 (Lc.exe) 的原理与源代码剖析
许可证编译器 (Lc.exe) 的作用是读取包含授权信息的文本文件,并产生一个可作为资源嵌入到公用语言运行库可执行文件中的 .licenses 文件. 在使用第三方类库时,经常会看到它自带的演示程序中 ...
- 【WP8.1开发】选择与搜索联系人
在需要的情况下,可以通过相关的API来访问手机上的联系人信息:当然,在不必要的情况下,不要随便去获取别人的数据. 要从联系人列表中选择并获取一位或者N位联系人的详细信息,比较简单的做法是利用Conta ...
- 使用AssetsLibrary.Framework创建多图片选择控制器(翻译)
系统的UIImagePickerController只能让用户选择单图片,而一般情况下,我们需要上传多张图片,这时应该可以同时选择多张图片,否则用户体验会很差.因此多图片选择器就诞生了. 在类库中,苹 ...
- 深入理解CSS元素可见性visibility
× 目录 [1]定义 [2]属性 [3]display[4]JS[5]transition [6]API[7]DEMO 前面的话 visibility属性常见于与display属性的比较中.但实际上, ...
- 【原创】.NET读写Excel工具Spire.Xls使用(5)重量级的Excel图表功能
本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4288836.html .NET读写Excel工具Spire.Xls使用文章 ...