HDU-5289<two pointers>
来源:互联网 发布:linux坏了怎么卸载 编辑:程序博客网 时间:2024/06/10 14:01
题意:
求一个数列中存在多少个区间,每个区间内的数的差不超过k;
思路:two_pointers;
#include<iostream>#include<cstdio>#include<set>#include<algorithm>using namespace std;const int N=1e5+5;int n,a[N],k;int main (){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) scanf("%d",a+i); multiset<int>m; long long ans=0; for(int l=1,r=1;l<=n;l++) { while(r<=n) { if(m.size()) if(a[r]-*m.begin()>=k||*m.rbegin()-a[r]>=k) break; m.insert(a[r++]); } ans+=r-l; m.erase(m.find(a[l])); } printf("%lld\n",ans); } return 0;}
0 0
- HDU-5289<two pointers>
- Two Pointers
- Two pointers
- Two pointers
- hdu 5288 OO’s Sequence(two pointers)
- HDU 5806 NanoApe Loves Sequence Ⅱ two pointers
- HDU 6194 string string string 后缀数组+lcp、Two Pointers
- Poj 3320(two pointers)
- Poj 2566(two pointers)
- Sum( two pointers )
- Array Two Pointers 总结
- hdu5806 two-pointers
- Odd Palindromes Two Pointers
- LeetCode--Two Pointers
- HDU 3629-Convex找凸四边形个数(扫描+二分/two pointers)
- poj2566 Bound Found -- Two pointers
- Leetcode - Pointers/Array - Two sum
- Two pointers技巧的应用
- iOS-关于键盘弹出和关闭
- 学习Java的第一个程序
- Android 智能短信第一天(下午)
- UVA - 694 The Collatz Sequence
- ubuntu上的网易云音乐
- HDU-5289<two pointers>
- 聊聊Android的缓存(四)
- bootstrap editable 动态改变列的编辑状态
- 网络编程中close和shutdown区别
- ios webview中二维码识别
- mongoDB add user in v3.0 问题的解决(Property 'addUser' of object admin is not a func)
- matlab实战中一些重要的函数总结
- 说说 Objective-C 里的 @()字面量语法
- Graph_tool的简单安装 ubuntu15.10