当前位置:网站首页>[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);
}
}
边栏推荐
- 7. Data permission annotation
- The biggest pain point of traffic management - the resource utilization rate cannot go up
- 基于STM32单片机设计的红外测温仪(带人脸检测)
- Huawei device command
- Nodejs教程之让我们用 typescript 创建你的第一个 expressjs 应用程序
- ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
- Detailed explanation of knowledge map construction process steps
- Comprehensive evaluation and recommendation of the most comprehensive knowledge base management tools in the whole network: flowus, baklib, jiandaoyun, ones wiki, pingcode, seed, mebox, Yifang cloud,
- 数据湖(八):Iceberg数据存储格式
- What is the problem with the SQL group by statement
猜你喜欢

ICML 2022 | flowformer: task generic linear complexity transformer

Data Lake (VIII): Iceberg data storage format

Aike AI frontier promotion (7.6)

20220211 failure - maximum amount of data supported by mongodb

What is the problem with the SQL group by statement

数据湖(八):Iceberg数据存储格式

ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer

Interviewer: what is the internal implementation of ordered collection in redis?

Distributed ID

Aiko ai Frontier promotion (7.6)
随机推荐
[asp.net core] set the format of Web API response data -- formatfilter feature
Math symbols in lists
Reflection operation exercise
It's almost the new year, and my heart is lazy
全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
1_ Introduction to go language
js通过数组内容来获取数组下标
【微信小程序】運行機制和更新機制
审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
Word bag model and TF-IDF
Nodejs教程之让我们用 typescript 创建你的第一个 expressjs 应用程序
2017 8th Blue Bridge Cup group a provincial tournament
OSPF multi zone configuration
基于STM32单片机设计的红外测温仪(带人脸检测)
如何实现常见框架
愛可可AI前沿推介(7.6)
2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
What are RDB and AOF
OAI 5G NR+USRP B210安装搭建