日志统计

双指针

#include
using namespace std;

#define x first
#define y second

typedef pair<int, int> PII;

const int N = 100005;
int n, d, k;
PII records[N];
int cnt[N];
bool st[N];

int main()
{
    cin >> n >> d >> k;
    for(int i = 0; i < n; i++) scanf("%d%d", &records[i].x, &records[i].y);
    
    sort(records, records + n);
    
    for(int i = 0, j = 0; i < n; i++)
    {
        int id = records[i].y;
        cnt[id]++;
        
        while(records[i].x - records[j].x >= d)
        {
            cnt[records[j].y]--;
            j++;
        }
        
        if(cnt[id] >= k) st[id] = true;
    }
    
    for(int i = 0; i < 100005; i++)
        if(st[i])
            printf("%d\n", i);
    return 0;
}

你可能感兴趣的:(日志统计)