天天看点

[蓝桥杯2018初赛]日志统计-双指针

[蓝桥杯2018初赛]日志统计-双指针
[蓝桥杯2018初赛]日志统计-双指针
[蓝桥杯2018初赛]日志统计-双指针

代码如下:

#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int>PII;
#define x first
#define y second
const int N = 100010;
bool st[N];
int n, d, k;
PII a[N];
int cnt[N];

int main() {
	cin >> n >> d >> k;
	for (int i = 0, j = 0; i < n; i++)
		cin >> a[i].x >> a[i].y;

	sort(a, a + n);

	for (int i = 0, j = 0; i < n; i++) {
		cnt[a[i].y]++;
		while (a[i].x - a[j].x >= d) {
			cnt[a[j].y]--;
			j++;
		}
		if (cnt[a[i].y] >= k)
			st[a[i].y] = true;
	}

	for (int i = 0; i < N; i++) {
		if (st[i])
			cout << i << endl;
	}
	return 0;
}