AcWing 1238. 日志统计

分析

在这里插入图片描述

代码

#include <iostream>
#include <cstring>
#include <algorithm>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N=1e5+5;
bool st[N];
int cnt[N];//记录i这个帖子当前的点赞数
PII log[N];//存下每一个时刻对某一个帖子的点赞信息
int main(){
    int n,k,d;
    cin >> n >> d >> k;
    for(int i=1;i<=n;i++)cin >> log[i].x >> log[i].y;
    sort(log+1,log+1+n);
    for(int i=1,j=1;i<=n;i++){
        int id=log[i].y;
        cnt[id]++;
        while(log[i].x-log[j].x>=d){//如果当前时刻比起点时刻的时间差大于等于d,就把超出的那部分减掉
            cnt[log[j].y]--;
            j++;
        }
        if(cnt[id]>=k)st[id]=true;
    }
    for(int i=1;i<=N;i++){
        if(st[i])cout << i << "\n";
    }
}
发布了175 篇原创文章 · 获赞 1 · 访问量 4250

猜你喜欢

转载自blog.csdn.net/weixin_45080867/article/details/104091392