多校#2 B
来源:互联网 发布:stm32定时器计算软件 编辑:程序博客网 时间:2024/04/27 17:38
#include <cstdio>#include <iostream>#include <queue>#include <set> #include <map>using namespace std;int n,k;int a[100005];int main(){int t;cin >> t;while(t--){cin >> n >> k;for(int i = 1;i <= n ;i++){scanf("%d",&a[i]);}int l = 1;int r = 1;long long int sum = 0;priority_queue<int,vector<int>,less<int> > ma;priority_queue<int,vector<int>,greater<int> > mi;map<int,int> mp;mp[a[l]] = 1;ma.push(a[l]);mi.push(a[l]);int maxa = a[l];int mina = a[l];long long int x;while(l <= n && r <= n ){while(maxa - mina < k && r <= n){r ++;if(mp.find(a[r])!=mp.end()){mp[a[r]]++;}else{mp[a[r]] = 1;}ma.push(a[r]);mi.push(a[r]);mina = mi.top();maxa = ma.top();};x = r-l;sum += x*(x+1)/2;do{mp[a[l]] --;while(mp[ma.top()]==0){ma.pop();}while(mp[mi.top()]==0){mi.pop();}maxa = ma.top();mina = mi.top();l++;}while(maxa - mina >= k && l <= r);x = r - l;sum -= x*(x+1)/2;}sum += x*(x+1)/2; cout << sum << endl;} return 0;}
0 0
- 多校#2 B
- 2b
- 2B
- B-2
- 2 B
- 1^b+2^b+3^b+...+n^b数列
- 汇编->a+b-2*(a and b)
- 一些2B的装B要求
- 2B面试问题
- 临时 2007-2b
- 2B面试问题
- IC2009#2B
- 2B青年
- B-树实现2
- Codeforces143Div.2-B
- 【dp】 Codeforces 2B
- 360,真2b
- 2:A-B Problem
- JS中定义对象方式四: 使用原型(prototype)方式创建对象之一
- Linux/Unix系统编程手册--SOCKET章节读书笔记
- HttpServletRequestWrapper的用法
- Snail—OC学习之类及对象
- 哈希表系列:初探哈希(二),c语言实现
- 多校#2 B
- 第5章面试2--专家打分
- 看看编译器是怎样用乘法代替除法的
- Python操作Mysql实例代码教程
- hdu 5289 Assignment
- dfs算法经典例题
- Android 安卓点击运行后 出错
- 最全面的linux信号量解析
- css前端笔试面试题