双指针并非要满足单调性才可以用,他也可以维护滑动窗口
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100010;
int n, d, k;
#define PII pair<int, int>
#define x first
#define y second
PII a[N];
int cnt[N];
int st[N];
int main(){
cin >> n >> d >> k;
for(int i = 0; i < n; i ++) scanf("%d%d", &a[i].x, &a[i].y);
sort(a, a + n);
for(int r = 0, l = 0; r < n; r ++){
int id = a[r].y;
cnt[id] ++;
while(a[r].x - a[l].x >= d){
cnt[a[l].y] --;
l ++;
}
if(cnt[id] >= k) st[id] = 1;
}
for(int i = 0; i <= 100000; i ++)
if(st[i]) cout << i << endl;
return 0;
}
原文:https://www.cnblogs.com/tomori/p/13732725.html