蓝桥杯每日一题2023.10.30

题目描述

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

题目分析

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

cpp 复制代码
#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;
} 
相关推荐
Hi李耶13 分钟前
【LeetCode】6-Z字形变换
算法·leetcode·职场和发展
菜小麒3 小时前
面试问题-01
面试·职场和发展
城管不管4 小时前
重生——第五次面试2026.8.1一面
java·数据库·后端·ai·面试·职场和发展·agent
代码代码快快显灵5 小时前
MYSQL—DAY1
面试·职场和发展
帅次1 天前
Android 应用高级面试:Window 近1年高频追问 18 题
android·面试·职场和发展
Hi李耶1 天前
【LeetCode】9-回文数
算法·leetcode·职场和发展
杨逢昌工厂6S管理2 天前
44-6S 管理回潮问题根治:归位三定闭环法的体系化落地路径|杨逢昌
经验分享·笔记·职场和发展·学习方法
程序员三藏2 天前
自动化测试详解
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
卡兹墨2 天前
iOS从打包到上架详细流程
ios·职场和发展·蓝桥杯