蓝桥杯 日志统计 (排序+尺取法)

 i指针在前,j指针在后,不断尺取长度小与 d 的区间。

// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO                       \
	ios::sync_with_stdio(false); \
	// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
P q[maxn];
int cnt[maxn];
bool st[maxn];
int main()
{
#ifdef WXY
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	IO;
	int n, d, k;
	cin >> n >> d >> k;
	for (int i = 0; i < n; i++)
		cin >> q[i].first >> q[i].second;
	sort(q, q + n); //  按照时刻从小到大排序
	for (int i = 0, j = 0; i < n; i++)
	{
		cnt[q[i].second]++; // 进来一个 i 那么当前时刻的日志获得赞的个数 + 1
		while (q[i].first - q[j].first >= d) // 左闭右开区间所以 区间长度必须 >= d
		{
			cnt[q[j++].second]--; // j 往后加一个 那么 j 代表 的日志不在当前区间,次数 - 1
		}
		if (cnt[q[i].second] >= k)
			st[q[i].second] = true;  // 当前日志点赞个数 >= k
	}
	for (int i = 0; i < maxn; i++)
		if (st[i] == true)
			cout << i << "\n";
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值