当前位置:网站首页>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;
}边栏推荐
猜你喜欢

628. Maximum product of three numbers

QT implementation fillet window

1323. Maximum number of 6 and 9

1605. Sum the feasible matrix for a given row and column

1005. Maximized array sum after K negations

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

969. Pancake sorting

807. Maintain the urban skyline

1529. Minimum number of suffix flips

读取和保存zarr文件
随机推荐
(POJ - 3186) treatments for the cows (interval DP)
Interval sum ----- discretization
Input can only input numbers, limited input
日期加1天
AcWing——第55场周赛
Ball Dropping
树莓派4B64位系统安装miniconda(折腾了几天终于解决)
1855. Maximum distance of subscript alignment
Raspberry pie 4B installation opencv3.4.0
What is the difficulty of programming?
Suffix expression (greed + thinking)
新手必会的静态站点生成器——Gridsome
Browser print margin, default / borderless, full 1 page A4
Codeforces Round #799 (Div. 4)A~H
2078. Two houses with different colors and the farthest distance
Discussion on QWidget code setting style sheet
Understand what is a programming language in a popular way
E. Breaking the Wall
C language must memorize code Encyclopedia
Configuration du cadre flask loguru log Library