AcWing 1238. 日志统计
原题链接
中等
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define x first
#define y second
typedef pair<int, int> pii;
const int N = 1e5 + 5;
int n, d, k;
pii logs[N];
int hot[N];//记录某贴是否曾经是热帖
int cnt[N];//记录某段时间内帖子出现过几次
int main(){
scanf("%d%d%d", &n, &d, &k);
for(int i = 0; i < n; i++) scanf("%d%d", &logs[i].x, &logs[i].y);
sort(logs, logs + n);//默认以X排序
int j = 0;
for(int i = 0; i < n; i++){
while(logs[j].x - logs[i].x < d && j < n){
cnt[logs[j].y]++;
if(cnt[logs[j].y] >= k) hot[logs[j].y] = 1;
j++;
}
cnt[logs[i].y]--;
}
for(int i = 0; i < N; i++){
if(hot[i] == 1) printf("%d\n", i);
}
return 0;
}