当前位置:网站首页>[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);
}
}
边栏推荐
- None of the strongest kings in the monitoring industry!
- The mail command is used in combination with the pipeline command statement
- el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
- Mtcnn face detection
- 【微信小程序】运行机制和更新机制
- Simple continuous viewing PTA
- 1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
- Deployment of external server area and dual machine hot standby of firewall Foundation
- Redis insert data garbled solution
- Spiral square PTA
猜你喜欢
Detailed explanation of knowledge map construction process steps
审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?
Laravel笔记-自定义登录中新增登录5次失败锁账户功能(提高系统安全性)
2017 8th Blue Bridge Cup group a provincial tournament
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
基于深度学习的参考帧生成
The biggest pain point of traffic management - the resource utilization rate cannot go up
039. (2.8) thoughts in the ward
Common English vocabulary that every programmer must master (recommended Collection)
C language operators
随机推荐
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
OSPF多区域配置
Why do job hopping take more than promotion?
Laravel notes - add the function of locking accounts after 5 login failures in user-defined login (improve system security)
3D人脸重建:从基础知识到识别/重建方法!
Entity alignment two of knowledge map
039. (2.8) thoughts in the ward
OneNote 深度评测:使用资源、插件、模版
Mtcnn face detection
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
None of the strongest kings in the monitoring industry!
Pinduoduo lost the lawsuit, and the case of bargain price difference of 0.9% was sentenced; Wechat internal test, the same mobile phone number can register two account functions; 2022 fields Awards an
SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍
Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]
【微信小程序】运行机制和更新机制
Spiral square PTA
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
What is the difference between procedural SQL and C language in defining variables
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
Xcode6 error: "no matching provisioning profiles found for application"