AcWing 1238. 日志统计
原题链接
中等
作者:
不知名的fE
,
2024-11-24 15:01:46
,
所有人可见
,
阅读 1
枚举时间段
import java.util.*;
import java.io.*;
public class Main {
static final int N = 100010;
static int[] cnt = new int[N];
static boolean[] st = new boolean[N];
static ArrayList<int[]> log = new ArrayList<>();
static int n, d, k;
public static void main(String[] args) throws IOException {
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
String[] str = sc.readLine().split(" ");
n = Integer.parseInt(str[0]);
d = Integer.parseInt(str[1]);
k = Integer.parseInt(str[2]);
while (n -- > 0) {
String[] s = sc.readLine().split(" ");
log.add(new int[]{Integer.parseInt(s[0]), Integer.parseInt(s[1])});
}
log.sort((o1, o2) -> {//排序
if (o1[0] != o2[0]) return o1[0] - o2[0];
return o1[1] - o2[1];
});
for (int i = 0, j = 0; i < log.size(); i++) {//j在i的左边
int[] t = log.get(i);//取出一条数据
cnt[t[1]]++;//帖子id++
while (t[0] - log.get(j)[0] >= d) {//保证在时间段d内
cnt[log.get(j)[1]]--;
j++;
}
if (cnt[t[1]] >= k) st[t[1]] = true;//标记
}
//枚举id的范围
for (int i = 0; i <= 100000; i++) if (st[i]) out.println(i);
out.flush();
}
}