当前位置:网站首页>Log statistics (double pointer)
Log statistics (double pointer)
2022-07-06 16:25:00 【AC__ dream】

This problem is a double pointer problem , Let's sort the likes by time , We set up i and j Respectively indicates that the current time period is less than k Hot post boundary , Each time the right boundary corresponds to id Zanga 1, If satisfied, praise equals k, Set as true, When the time period is greater than k When the current left boundary is represented id Praise and subtract 1, Enumerate , Until the end , What needs attention is the boundary problem , See the code for details :
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
const int N=1e5+10;
bool vis[N];
int n,d,k,cnt[N];
struct node{
int ts,id;
}p[N];
bool cmp(node a,node b)
{
return a.ts<b.ts;
}
int main()
{
cin>>n>>d>>k;
for(int i=1;i<=n;i++)
scanf("%d%d",&p[i].ts,&p[i].id),p[i].id++;
sort(p+1,p+n+1,cmp);
cnt[p[0].id]++;
for(int i=0,j=1;j<=n;i++)
{
while(p[j].ts-p[i].ts<d&&j<=n)
{
cnt[p[j].id]++;
if(cnt[p[j].id]==k) vis[p[j].id]=true;
j++;
}
cnt[p[i].id]--;
}
for(int i=1;i<=100001;i++)
if(vis[i]) printf("%d\n",i-1);
return 0;
}边栏推荐
- Input can only input numbers, limited input
- 日期加1天
- Codeforces Round #798 (Div. 2)A~D
- C language is the watershed between low-level and high-level
- 图图的学习笔记-进程
- Flask框架配置loguru日志库
- Generate random password / verification code
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- 860. Lemonade change
- Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)
猜你喜欢

QT按钮点击切换QLineEdit焦点(含代码)

Problem - 922D、Robot Vacuum Cleaner - Codeforces

QT实现圆角窗口

QT模拟鼠标事件,实现点击双击移动拖拽等

Advancedinstaller installation package custom action open file

409. Longest palindrome

B - Code Party (girls' competition)

Openwrt source code generation image

C language learning notes

Radar equipment (greedy)
随机推荐
本地可视化工具连接阿里云centOS服务器的redis
计算时间差
Programmers, what are your skills in code writing?
Codeforces Round #801 (Div. 2)A~C
Codeforces Round #803 (Div. 2)A~C
QT simulates mouse events and realizes clicking, double clicking, moving and dragging
useEffect,函數組件掛載和卸載時觸發
Acwing: Game 58 of the week
顺丰科技智慧物流校园技术挑战赛(无t4)
Data storage in memory & loading into memory to make the program run
QT implementation fillet window
Install Jupiter notebook under Anaconda
1605. Sum the feasible matrix for a given row and column
Advancedinstaller installation package custom action open file
Codeforces Round #802(Div. 2)A~D
Discussion on QWidget code setting style sheet
AcWing:第56场周赛
Acwing - game 55 of the week
Opencv learning log 29 -- gamma correction
The concept of C language array