[蓝桥杯 2018 省 B] 日志统计
题目描述
小明维护着一个程序员论坛。现在他收集了一份“点赞”日志,日志共有
N
N
N 行。其中每一行的格式是 ts id
,表示在
t
s
ts
ts 时刻编号
i
d
id
id 的帖子收到一个“赞”。
现在小明想统计有哪些帖子曾经是“热帖”。如果一个帖子曾在任意一个长度为 D D D 的时间段内收到不少于 K K K 个赞,小明就认为这个帖子曾是“热帖”。
具体来说,如果存在某个时刻 T T T 满足该帖在 [ T , T + D ) [T,T+D) [T,T+D) 这段时间内(注意是左闭右开区间)收到不少于 K K K 个赞,该帖就曾是“热帖”。
给定日志,请你帮助小明统计出所有曾是“热帖”的帖子编号。
输入格式
第一行包含三个整数 N N N、 D D D 和 K K K。
以下 N N N 行每行一条日志,包含两个整数 t s ts ts 和 i d id id。
输出格式
按从小到大的顺序输出热帖 i d id id。每个 i d id id 一行。
样例 #1
样例输入 #1
7 10 2
0 1
0 10
10 10
10 1
9 1
100 3
100 3
样例输出 #1
1
3
提示
对于 50 % 50\% 50% 的数据, 1 ≤ K ≤ N ≤ 1000 1 \le K \le N \le 1000 1≤K≤N≤1000。
对于 100 % 100\% 100% 的数据, 1 ≤ K ≤ N ≤ 1 0 5 1 \le K \le N \le 10^5 1≤K≤N≤105, 0 ≤ i d , t s ≤ 1 0 5 0 \le id, ts \le 10^5 0≤id,ts≤105。
时限 1 秒, 256M。蓝桥杯 2018 年第九届省赛
AC代码:
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<iomanip>
#define endl '\n'
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=1e9 + 7;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;
typedef pair<int, int>PII;
int n, d, k;
PII q[N];
int st[N];
int cnt[N];
int main()
{
cin >> n >> d >> k;
for(int i = 1; i <= n; i ++)
{
cin >> q[i].x >> q[i].y;
}
sort(q + 1, q + 1 + n);
for(int i = 1, j = 1; i <= n; i ++)
{
int t = q[i].y;
cnt[t] ++;//记录的是每个时间段出现的帖子的数目
while(q[i].x - q[j].x >= d)
{
cnt[q[j].y] --;
j ++;
}
if(cnt[t] >= k) st[t] = 1;
}
for(int i = 0; i <= 100000; i ++)
{
if(st[i]) cout << i << endl;
}
return 0;
}