1238. 日志统计 蓝桥杯

https://www.acwing.com/problem/content/description/1240/

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e5+10;
int n,d,k;
int cnt[N];
bool bk[N];
struct node
{
    
    
    int ts,id;
    bool operator<(const node &w) const
    {
    
    
        return ts<w.ts;
    }
}a[N];
int main()
{
    
    
    ios::sync_with_stdio(false);
    cin>>n>>d>>k;
    for(int i=0;i<n;i++) cin>>a[i].ts>>a[i].id;
    sort(a,a+n);
    memset(bk,false,sizeof bk);
    for(int i=0,j=0;i<n;i++)    //i为快指针,j为慢指针,在d时间内,cnt[id]++,超过了就--,大于k时及时标记,这样后边即使被--,也不影响
    {
    
    
        int id=a[i].id;
        cnt[id]++;
        while(a[i].ts-a[j].ts>=d)
        {
    
    
            cnt[a[j].id]--;
            j++;
        }
        if(cnt[id]>=k) bk[id]=true;
    }
    
    for(int i=0;i<=100000;i++)   //注意是1e5
        if(bk[i])
            cout<<i<<"\n";
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_52341477/article/details/121132622