蓝桥杯每日一题2023.10.30

题目描述

日志统计 - 蓝桥云课 (lanqiao.cn)

题目分析

本题可以使用双指针来维护时间段的区间,在维护的时间段内确定是否为热帖

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int N = 2e5 + 10;
struct node
{
	int t, id;
}tiee[N];
int n, d, k, cnt[N];
set<int> st;
bool cmp(node a, node b)
{
	return a.t < b.t;
}
int main()
{
	cin >> n >> d >> k;
	for(int i = 1; i <= n; i ++)
	{
		cin >> tiee[i].t >> tiee[i].id;
	}
	sort(tiee + 1, tiee + 1 + n, cmp);
	for(int i = 1, j = 1; i <= n; i ++)
	{
		cnt[tiee[i].id] ++;//cnt[id]表示同一个id获赞数 
		while(tiee[i].t - tiee[j].t >= d)//两个帖子的时间相差超过d说明该赞无效 
		{
			cnt[tiee[j].id] --;//无效的id需要被减掉 
			j ++; 
		} 
		int x = tiee[i].id;
		if(cnt[tiee[i].id] >= k)st.insert(x);//set自动排序去重 
	}
	for(auto i : st)cout << i << '\n';
	return 0;
} 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值