题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2093

找第k近的可以用一个含k个元素的滑动窗口来实现。

卡空间也还行,但卡时间。不要预处理倍增数组再计算,开一维,一边处理倍增数组一边算答案。不要每次算M次,for(;m;m>>=1)更快。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e6+,M=;
int n,K,hd,tl,to[N],tt[N],ans[N];
ll m,dis[N];
int rdn()
{
int ret=;char ch=getchar();
while(ch>''||ch<'')ch=getchar();
while(ch>=''&&ch<='')(ret*=)+=ch-'',ch=getchar();
return ret;
}
ll rdl()
{
ll ret=;char ch=getchar();
while(ch>''||ch<'')ch=getchar();
while(ch>=''&&ch<='')(ret*=)+=ch-'',ch=getchar();
return ret;
}
int main()
{
n=rdn();K=rdn();m=rdl();K++; //zj是第一近
for(int i=;i<=n;i++)dis[i]=rdl();
hd=;tl=K;
for(int i=;i<=n;i++)
{
ans[i]=i;
while(tl<n&&dis[tl+]-dis[i]<dis[i]-dis[hd])hd++,tl++;
to[i]=(dis[tl]-dis[i]>dis[i]-dis[hd]?tl:hd);
}
if(m&)
for(int i=;i<=n;i++)ans[i]=to[ans[i]];
m>>=;
for(;m;m>>=)
{
for(int j=;j<=n;j++) tt[j]=to[to[j]];
if(m&) for(int j=;j<=n;j++) ans[j]=tt[ans[j]];
for(int j=;j<=n;j++) to[j]=tt[j];
}
for(int i=;i<=n;i++)printf("%d ",ans[i]);
return ;
}

bzoj 2093 [Poi2010]Frog——滑动窗口的更多相关文章

  1. BZOJ 2093: [Poi2010]Frog

    Description 从一个点到达与他距离第 \(k\) 小的点,问从每个点跳 \(m\) 次到达那个点. Sol 队列+倍增. 保持队列里的元素个数为 \(k\) ,从前往后扫不难发现左右端点都是 ...

  2. bzoj 2093 [ Poi 2010 ] Frog —— 滑动窗口 + 倍增

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2093 先处理出每个点第一次会跳到哪里: 开一个长度为 K+1 的窗口(因为第一近的实际是自己 ...

  3. bzoj2093: [Poi2010]Frog(单调队列,倍增)

    2093: [Poi2010]Frog Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 568  Solved: 186[Submit][Status] ...

  4. [LeetCode] Sliding Window Maximum 滑动窗口最大值

    Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...

  5. TCP/IP 协议中的滑动窗口

    一个例子明白发送缓冲区.接受缓冲区.滑动窗口协议之间的关系. 在上面的几篇文章中简单介绍了上述几个概念在TCP网络编程中的关系,也对应了几个基本socket系统调用的几个行为,这里再列举一个例子,由于 ...

  6. Storm Windowing storm滑动窗口简介

    Storm Windowing 简介 Storm可同时处理窗口内的所有tuple.窗口可以从时间或数量上来划分,由如下两个因素决定: 窗口的长度,可以是时间间隔或Tuple数量: 滑动间隔(slidi ...

  7. lintcode 滑动窗口的最大值(双端队列)

    题目链接:http://www.lintcode.com/zh-cn/problem/sliding-window-maximum/# 滑动窗口的最大值 给出一个可能包含重复的整数数组,和一个大小为  ...

  8. TCP 三次握手四次挥手, ack 报文的大小.tcp和udp的不同之处、tcp如何保证可靠的、tcp滑动窗口解释

    一.TCP三次握手和四次挥手,ACK报文的大小 首先连接需要三次握手,释放连接需要四次挥手 然后看一下连接的具体请求: [注意]中断连接端可以是Client端,也可以是Server端. [注意] 在T ...

  9. tcp协议头窗口,滑动窗口,流控制,拥塞控制关系

    参考文章 TCP 的那些事儿(下) http://coolshell.cn/articles/11609.html tcp/ip详解--拥塞控制 & 慢启动 快恢复 拥塞避免 http://b ...

随机推荐

  1. Write 语句

    ABAP Write 语句 转载▼http://blog.sina.com.cn/s/blog_5ccd375b0100ghhi.html   1.Write 叙述 ABAP/4 用来在屏幕上输出数据 ...

  2. 在网页中显示PDF文件及vue项目中弹出PDF

    1.<embed width="800" height="600" src="test_pdf.pdf"> </embed ...

  3. shell编程1

    shell编程1 一.shell基础正则表达式 1.正则表达式和通配符 正则表达式是用来在文件中匹配符合条件的字符串,正则式包含匹配.(grep awk sed) 通配符是用来匹配符合条件的文件名,通 ...

  4. 在linux系统下Git源码系统的文件下载

    Git是一个开源的分布式版本控制系统,在linux系统中下载git中的文件使用repo的很多. 网上有很多repo下载的地址失效,目前可用的链接在这里记录一下. 没有安装git的安装一下: sudo ...

  5. hbase shell-security(安全指令)

    hbase shell安全指令篇: grant list_security_capabilities revoke user_permission 正在编辑中

  6. OJ 之 FATE

                                            - FATE Crawling in process... Crawling failed Time Limit:100 ...

  7. 如何在unigui中用代码展开一棵树?

    procedure expandtree(tree:tunitreeview);begin   UniSession.AddJS('setTimeout("' + Tree1.JSName ...

  8. win7 apache+openssl 安装

    win7 apache+openssl 安装 博客分类: win7 apache+openssl 安装 win7 apache+openssl 安装  注:附件提供包含apache和openssl的安 ...

  9. Qt中 QTableWidget用法总结

    转自--> http://edsionte.com/techblog/archives/3014 http://hi.baidu.com/fightiger/item/693aaa0f0f87d ...

  10. CSS: iPhone Custom CSS

    1. [代码][CSS]代码 <style type="text/css" media="screen"> /* iPhone 4@media on ...