Blue Bridge - Log Statistical Ruler

Idea: Put the same id together and sort by time from small to large to judge
. The point with a big pit is that the id starts from 0! ! ! Too pit! ! !
Here is the c code:

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#define ll long long
#define inf 0x3f3f3f3f
#define sd(a) scanf("%d",&a)
#define sdd(a,b) scanf("%d%d",&a,&b)
#define cl(a,b) memset(a,b,sizeof(a))
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dbg() printf("aaa\n")
using namespace std;
const int maxn=1e5+10;
int n,d,t;
struct node{
    
    
    int id,ts;
    bool operator<(const node &oth)const{
    
    
        return ts<oth.ts;
    }
}a[maxn];
vector<int> g[maxn];
priority_queue<int,vector<int>,greater<int> > ans;
int main() {
    
    
	sddd(n,d,t);
    rep(i,1,n){
    
    
        sdd(a[i].ts,a[i].id);
    }
    int maxid=0;
    sort(a+1,a+n+1);
    rep(i,1,n){
    
    
        g[a[i].id].push_back(a[i].ts);
        if(maxid<a[i].id) maxid=a[i].id;
    }
    rep(i,0,maxid){
    
    //对于每一个帖子
        if(g[i].size()==0) continue;
        int j=0,k=0;
        int maxx=0;//当前这个最多几个赞
        while(k<g[i].size()){
    
    //尺取法
            if(g[i][j]+d>g[i][k]){
    
    //若时间段符合条件
                if(maxx<k-j+1) maxx=k-j+1;
                k++;
            }else{
    
    
                j++;
            }
            if(maxx>=t) break;
        }
        if(maxx>=t) ans.push(i);
    }
    while(!ans.empty()){
    
    
        printf("%d\n",ans.top());
        ans.pop();
    }
	return 0;
}

Topic description
Xiaoming maintains a programmers forum. Now he has collected a "like" log, which has N lines in total. The format of each line is:

ts id

Indicates that the post with the ID number at time ts received a "like".

Now Xiao Ming wants to count which posts were once "hot posts". If a post has received no less than K likes in any time period of length D, Xiao Ming considers the post to be a "hot post".

Specifically, if there is a certain moment T that satisfies that the post receives no less than K likes within the period of [T, T+D) (note that it is in the left-closed and right-open interval), the post was once "hot" post".

Given the log, please help Xiaoming to count all the post numbers that were "hot posts".
Input
The first line contains three integers N, D, and K.
The following N lines have one log per line, containing two integers ts and id.

For 50% of the data, 1 <= K <= N <= 1000
For 100% of the data, 1 <= K <= N <= 100000 0 <= ts <= 100000 0 <= id <= 100000
output
in ascending order Large order output hot post id. One row per id.
sample input

7 10 2
0 1
0 10
10 10
10 1
9 1
100 3
100 3

Sample output

1
3

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326041973&siteId=291194637