AcWing 1238. 日志统计
原题链接
中等
作者:
Bill0112
,
2025-01-15 00:05:16
,
所有人可见
,
阅读 1
java 代码
import java.util.*;
public class Main {
static class PII implements Comparable<PII> {
int x, y;
PII(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(PII other) {
return Integer.compare(this.x, other.x);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int d = scanner.nextInt();
int k = scanner.nextInt();
PII[] logs = new PII[n];
for (int i = 0; i < n; i++) {
logs[i] = new PII(scanner.nextInt(), scanner.nextInt());
}
Arrays.sort(logs);
boolean[] st = new boolean[100010];
int[] cnt = new int[100010];
for (int i = 0, j = 0; i < n; i++) {
int t = logs[i].y;
cnt[t]++;
while (logs[i].x - logs[j].x >= d) {
cnt[logs[j].y]--;
j++;
}
if (cnt[t] >= k) {
st[t] = true;
}
}
for (int i = 0; i <= 100000; i++) {
if (st[i]) {
System.out.println(i);
}
}
scanner.close();
}
}