当前位置:网站首页>[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
2022-07-06 21:09:00 【Twilight_ years】
Ideas : The maximum length of the interval is D,id and t After pairing , Sort by time , Maintain the interval with double pointers , The maximum length of this interval shall not exceed D.
cnt[id] Current interval record id Number of occurrences .
st[id] Record id Is it a hot post .
Only the right and left endpoints of the interval need to be maintained .
Reference resources ACWING Pear painted Xiaotang The antithesis of :
AcWing 1238. Log statistics - 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);
}
}
边栏推荐
- 1500萬員工輕松管理,雲原生數據庫GaussDB讓HR辦公更高效
- Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]
- R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
- 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
- 全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
- 爱可可AI前沿推介(7.6)
- 基于深度学习的参考帧生成
- Mtcnn face detection
- @PathVariable
- How to turn a multi digit number into a digital list
猜你喜欢
Infrared thermometer based on STM32 single chip microcomputer (with face detection)
PHP online examination system version 4.0 source code computer + mobile terminal
【微信小程序】運行機制和更新機制
基于深度学习的参考帧生成
What key progress has been made in deep learning in 2021?
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
Detailed explanation of knowledge map construction process steps
【微信小程序】运行机制和更新机制
Interviewer: what is the internal implementation of ordered collection in redis?
[MySQL] trigger
随机推荐
C # use Oracle stored procedure to obtain result set instance
全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
过程化sql在定义变量上与c语言中的变量定义有什么区别
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
R language visualizes the relationship between more than two classification (category) variables, uses mosaic function in VCD package to create mosaic plots, and visualizes the relationship between tw
代理和反向代理
C language operators
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
Swagger UI教程 API 文档神器
Interviewer: what is the internal implementation of ordered collection in redis?
面试官:Redis中有序集合的内部实现方式是什么?
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
ICML 2022 | flowformer: task generic linear complexity transformer
3D人脸重建:从基础知识到识别/重建方法!
【微信小程序】运行机制和更新机制
[MySQL] trigger
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
Common English vocabulary that every programmer must master (recommended Collection)
Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
Variable star --- article module (1)