当前位置:网站首页>"Hot post" Statistics
"Hot post" Statistics
2022-06-26 01:31:00 【Stay--hungry】

struct log
{
int t, id;
bool operator<(const log &L) const
{
return t < L.t;
}
} logs[N];
Simple approach
Enumerate all of length D D D Time period , Statistics in this time period , Number of likes received per post , Thus it is concluded that “ Hot post ”.
sort(logs, logs + n); // Sort all likes by time
for (int t = 0; t <= 100001 - D; t ++) // Enumerate each time period
{
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; i ++) // Traverse each record
if (t <= logs[i].t && logs[i].t < t + D) // The likes are recorded in this time period
{
int id = logs[i].id;
cnt[id] ++;
if (cnt[id] >= K) st[id] = true;
}
}
TLE
Double pointer method
be aware : The first i i i Time period and i + 1 i+1 i+1 There are many records in the same time period .
So double pointers are used to traverse all records , Maintenance pointer j , i j,i j,i Make it long D D D Both ends of the time period .
Be careful : Because it enumerates in order , i i i Each movement of the pointer will increase the number of likes of a post , therefore i i i The movement of the pointer produces “ Hot post ” Direct guidance of , That is, the latest “ Hot post ” It must be i i i The post pointed to , So just judge each time i i i Whether the post referred to by the pointer is a hot post .
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010;
struct log
{
int t, id;
bool operator< (const log &L) const
{
return t < L.t;
}
} logs[N];
int cnt[N];
bool st[N]; // st[id] Recording posts id Is it a hot post
int main()
{
int n, D, K;
cin >> n >> D >> K;
for (int i = 0; i < n; i ++) cin >> logs[i].t >> logs[i].id;
sort(logs, logs + n); // Sort the likes by time
for (int i = 0, j = 0; i < n; i ++) // Double pointer enumerates each record ,j、i Points to both ends of the time period
{
int id = logs[i].id; //i Point to a new record
cnt[id] ++;
while (logs[j].t + D <= logs[i].t) cnt[logs[j].id] --, j ++; // adjustment j, send j~i In the same time period
if (cnt[id] >= K) st[id] = true; // In this time period ,id It's a hot post
}
for (int id = 0; id <= 100000; id ++)
if (st[id]) cout << id << endl;
return 0;
}
边栏推荐
- 开窍之问答
- Computer network knowledge summary (interview)
- 毕业季你考虑好去留了吗
- Freertos+stm32l+esp8266+mqtt protocol transmits temperature and humidity data to Tencent cloud IOT platform
- --都市修炼手册之SQL-- 第一章 基础复习
- 经纬度 多点 获取中心点 已解决
- Dgus new upgrade: fully support digital video playback function
- 基金开户安全吗?有没有什么风险?
- 快速生成1~20自然数,并轻松复制
- 同花顺上登录股票账户是安全的吗?同花顺上是如何开股票账户的
猜你喜欢
随机推荐
Using redis database as cache in Django
STM32GPIO
Is it safe to open a fund account? Are there any risks?
JSON introduction
The kth largest element in the array
智慧家——全家具功能
如何有效地推广产品
Download and install flume
[flower carving experience] 11 start esp32c3
Oracle数据库完全卸载步骤(暂无截图)
CityJSON
Redis strings command
Reading notes on how to connect the network - hubs, routers and routers (III)
Flex & bison start
Xinku online | cnopendata text data of IPO declaration and issuance of A-share listed companies
What is the process of opening a mobile card account? Is it safe to open an account online?
Idempotence of interfaces -- talk about idempotence of interfaces in detail, that is, solutions
Shengxin weekly issue 33
2022防爆电气操作证考试题库及模拟考试
使用Gin框架运行Demo时报错“ listen tcp :8080: bind: An attempt was made to access a socket in a way forbidden”







![[excel knowledge and skills] Excel data type](/img/f6/e1ebe033d1a2a266ebda00b10098ed.png)

