solution.cpp 809 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <iostream>
#include <algorithm>

using namespace std;
const int N = 1e5 + 10;
typedef pair<int, int> PII;
#define x first
#define y second
PII logs[N];
bool st[N];
int cnt[N];

int main()
{
    int n, d, k;
    cin >> n >> d >> k;
    for (int i = 0; i < n; i++)
        cin >> logs[i].x >> logs[i].y; //时间,编号

    sort(logs, logs + n); //按照时间先排序

    for (int i = 0, j = 0; i < n; i++)
    {
        cnt[logs[i].y]++; //目标编号出现次数加1
        while (logs[i].x - logs[j].x >= d)
            cnt[logs[j].y]--, j++; //滑动窗口,保证目标区域合法
        if (cnt[logs[i].y] >= k)
            st[logs[i].y] = true; //如果编号次数超K则输出
    }

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