蓝桥杯每日一题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;
} 
相关推荐
元亓亓亓3 天前
LeetCode热题100--105. 从前序与中序遍历序列构造二叉树--中等
算法·leetcode·职场和发展
测试老哥3 天前
Selenium 使用指南
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
仙俊红3 天前
LeetCode每日一题,20250914
算法·leetcode·职场和发展
前端小超超3 天前
capacitor配置ios应用图标不同尺寸
ios·蓝桥杯·cocoa
睡不醒的kun4 天前
leetcode算法刷题的第三十四天
数据结构·c++·算法·leetcode·职场和发展·贪心算法·动态规划
吃着火锅x唱着歌4 天前
LeetCode 1446.连续字符
算法·leetcode·职场和发展
武子康4 天前
AI-调查研究-76-具身智能 当机器人走进生活:具身智能对就业与社会结构的深远影响
人工智能·程序人生·ai·职场和发展·机器人·生活·具身智能
Nan_Shu_6144 天前
Web前端面试题(1)
前端·面试·职场和发展
YuTaoShao4 天前
【LeetCode 每日一题】3000. 对角线最长的矩形的面积
算法·leetcode·职场和发展
007php0075 天前
Redis高级面试题解析:深入理解Redis的工作原理与优化策略
java·开发语言·redis·nginx·缓存·面试·职场和发展