当前位置:网站首页>【滑动窗口】第九届蓝桥杯省赛B组:日志统计
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
2022-07-06 12:51:00 【暮色_年华】

思路:区间最大长度为D,id和t配对后,按照时间排序,用双指针维护区间,这个区间长度最大长度不超过D。
cnt[id]记录当前区间id出现次数。
st[id]记录id是否为热帖。
只需要维护区间的右端点和左端点的情况。
参考ACWING梨绘小棠 的题解:

import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
static final int N=100010;
static int n,d,k;
static int[] cnt=new int[N];
static boolean[] st=new boolean[N];
static PII[] logs= new PII[N];
public static void main(String[]args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[]s=br.readLine().split(" ");
n=Integer.parseInt(s[0]);
d=Integer.parseInt(s[1]);
k=Integer.parseInt(s[2]);
for(int i=0;i<n;i++){
String[]str=br.readLine().split(" ");
int t=Integer.parseInt(str[0]);
int id=Integer.parseInt(str[1]);
logs[i]=new PII(t,id);
}
Arrays.sort(logs,0,n);
for(int i=0,j=0;i<n;i++){
cnt[logs[i].id]++;
while(logs[i].t-logs[j].t>=d){
cnt[logs[j].id]--;
j++;
}
if(cnt[logs[i].id]>=k)st[logs[i].id]=true;
}
for(int i=0;i<N;i++){
if(st[i]==true)System.out.println(i);
}
}
}
class PII implements Comparable<PII>{
int t,id;
public PII(int t,int id){
this.t=t;
this.id=id;
}
public int compareTo(PII o){
return Integer.compare(t,o.t);
}
}
边栏推荐
- Opencv learning example code 3.2.3 image binarization
- js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
- Reference frame generation based on deep learning
- 【论文解读】用于白内障分级/分类的机器学习技术
- 自定义限流注解
- 愛可可AI前沿推介(7.6)
- Reinforcement learning - learning notes 5 | alphago
- 字符串的使用方法之startwith()-以XX开头、endsWith()-以XX结尾、trim()-删除两端空格
- 性能测试过程和计划
- Reflection operation exercise
猜你喜欢

OAI 5g nr+usrp b210 installation and construction

Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)

Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices

The biggest pain point of traffic management - the resource utilization rate cannot go up

Variable star --- article module (1)

The most comprehensive new database in the whole network, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, flying Book Multidimensional table, heipayun, Zhix

拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条

Laravel笔记-自定义登录中新增登录5次失败锁账户功能(提高系统安全性)

愛可可AI前沿推介(7.6)

968 edit distance
随机推荐
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
(work record) March 11, 2020 to March 15, 2021
R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
JS操作dom元素(一)——获取DOM节点的六种方式
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
使用.Net驱动Jetson Nano的OLED显示屏
Regular expression collection
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
None of the strongest kings in the monitoring industry!
过程化sql在定义变量上与c语言中的变量定义有什么区别
SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍
##无yum源安装spug监控
Minimum cut edge set of undirected graph
Manifest of SAP ui5 framework json
1_ Introduction to go language
2017 8th Blue Bridge Cup group a provincial tournament
Detailed explanation of knowledge map construction process steps
for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
PHP saves session data to MySQL database
2110 summary of knowledge points and common problems in redis class