アイデア:
ダブルポインターアルゴリズムを使用して、jを使用して最初を指し、iを使用して最後を指し、次に右に連続的に移動し、一度に1つのコードのみを変更し
ます。
# include<iostream>
# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std;
# define x first
# define y second
const int N = 100010;
int n,d,k;
typedef pair<int,int> PII;
PII logs[N];
int cnt[N];
bool st[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);
for(int i = 0,j = 0;i < n;i++)
{
int id = logs[i].y;
cnt[id]++;
//i点在不断的往前走,直到i减去j的距离大于d时,就去掉在j的时候获得的赞,然后j往前走一步
while(logs[i].x - logs[j].x >= d)/
{
cnt[logs[j].y]--;
j++;
}
if(cnt[logs[i].y] >= k)
{
st[logs[i].y] = true;
}
}
for(int i = 0;i < N;i++)
{
if(st[i] == true)
{
printf("%d\n",i);
}
}
return 0;
}