日志统计

#include<iostream>
#include<algorithm>
#define x first
#define y second
using namespace std;
typedef  pair<int,int> PII;
const int N = 1e5 + 10;
bool tr[N];
PII a[N];
int cnt[N];
int main()
{
	int n, d, k;
	cin >> n >> d >> k;
	for(int i = 1; i <= n; i ++)cin >>a[i].x >> a[i].y;
	sort(a + 1,a + 1 +n);
	for(int i = 1, j = 1; i <= n; i ++)
	{
		int t = a[i].y;
		cnt[t] ++;
		while(a[i].x-a[j].x >= d)
		{
			cnt[a[j].y] --;
			j ++;
		}
		if(cnt[t] >=k ){
			tr[t] = true;
		}
	}
	for(int i = 1;i <= 100010; i ++)
	{
		if(tr[i] == true)cout << i <<endl;
	}
}
用双指针维护一段不大于d的区间,统计在这个区间内,各个id所获得的赞。
全部评论

相关推荐

10-09 16:12
门头沟学院 Java
帅宇殿下:佬,简历写的什么
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务