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 ...
随机推荐
- 知方可补不足~sqlserver中使用sp_who查看sql的进程
回到目录 在SQLSERVER中每个会话,即每个查询分析器窗口都会产生一个SQL进程,对于那些持续时间短的进程,它们转瞬即失,而对于持续时间比较长的,我们需要希望查看它的运行状态,就可以借助SQL提供 ...
- js笔记——js异常处理
异常捕获 try...catch结构: try { //需要捕获的代码块 } catch (e) { console.log(e.name + ": " + e.message); ...
- lua表排序
对于lua的table排序问题,一般的按照value值来排序,使用table.sort( needSortTable , func)即可(可以根据自己的需要重写func,否则会根据默认来:默认的情形之 ...
- Atititi tesseract使用总结
Atititi tesseract使用总结 消除bug,优化,重新发布.当前版本为3.02 项目下载地址为:http://code.google.com/p/tesseract-ocr. Window ...
- java实现栈与队列
一.栈 栈是一种特殊的线性表.其特殊性在于限定插入和删除数据元素的操作只能在线性表的一端进行.(先进后出) 访问权限:栈限制了访问权限,只可以访问尾节点,也就是最后添加的元素 即栈顶的元素 /** * ...
- python+selenium运行报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
使用python+selenium运行自动化脚本时,打印某一段文字出现UnicodeEncodeError: 'ascii' codec can't encode characters in posi ...
- 如果正确读取SQL Server中的扩展事件?
SQL Server中使用扩展事件捕捉所需的信息后,可以选择存放的位置.比如说内存或文件中,但无论存在哪里,其本质都是一个大XML.因此在SQL Server中读取该XML就是解析扩展事件结果 ...
- ObjectOutputStream和ObjectInputStream
官方解释: ObjectOutputStream 将 Java 对象的基本数据类型和图形写入 OutputStream.可以使用 ObjectInputStream 读取(重构)对象.通过使用流中的文 ...
- php代码习惯(一)
1: 利用sprintf来绑定变量,分离绑定的参数与语句 $query = sprintf("SELECT * FROM users WHERE user='%s' AND password ...
- MFC 字符串类CString 源代码
原文:http://blog.csdn.net/benny5609/article/details/1926088 CString使用的是引用技术,可以共享数据(这个大家都知道),另外空的CStirn ...