题目链接

思路

非常有趣的一道题。

先考虑如何找出第K远的位置。

因为给出的序列是单调的,所以对于位置\(i\)的前\(K\)远位置肯定是一个包含位置\(i\)的长度为\(k+1\)的区间。我们用\(l\)表示这个区间的左端点,\(r\)表示这个区间的右端点。那么当\(i+1\)时,\(l\)和\(r\)都只会往右挪。而且往右挪的条件是第\(r+1\)个点与\(i+1\)的距离比第\(l\)个点与第\(i+1\)个点的距离小。

这样就可以找出每个位置的第k远位置。然后就得到了一个置换。

跳\(m\)次也就相当于把这个置换循环\(m\)次。依据倍增的思想只要\(nlogm\)的复杂度就可以完成了。

代码

#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 1000000 + 100; ll read() {
ll x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c <= '9' && c >= '0') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
ll a[N];
int b[N],n,k;
ll m;
int tmp[N],c[N];
void calc() {
for(int i = 1;i <= n;++i) c[i] = tmp[i];
for(int i = 1;i <= n;++i) tmp[i] = c[tmp[i]];
}
int main() {
n = read(),k = read(),m = read();\
for(int i = 1;i <= n;++i) a[i] = read();
int l = 1,r = min(k + 1,n);
for(int i = 1;i <= n;++i) {
while((l < i && r < n && a[r + 1] - a[i] < a[i] - a[l]) || r < i) {
++l;++r;
}
if(a[i] - a[l] >= a[r] - a[i]) tmp[i] = l;
else tmp[i] = r;
b[i] = i;
}
for(;m;m >>= 1,calc()) {
if(m & 1) for(int i = 1;i <= n;++i) b[i] = tmp[b[i]];
} for(int i = 1;i <= n;++i)
printf("%d ",b[i]);
return 0;
}

bzoj2093 Frog的更多相关文章

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

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

  2. BZOJ2093 : [Poi2010]Frog

    从左往右维护两个指针l,r表示离i最近的k个点的区间,预处理出每个点出发的后继,然后倍增. #include<cstdio> typedef long long ll; const int ...

  3. [LeetCode] Frog Jump 青蛙过河

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  4. hdu5037 Frog (贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=5037 网络赛 北京 比较难的题 Frog Time Limit: 3000/1500 MS (Java/Othe ...

  5. CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&&当然暴力is also no problem)

    C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. Frog Jump

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  7. POJ 1054 The Troublesome Frog

    The Troublesome Frog Time Limit: 5000MS Memory Limit: 100000K Total Submissions: 9581 Accepted: 2883 ...

  8. Leetcode: Frog Jump

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  9. hdu 4004 The Frog's Games

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...

随机推荐

  1. Go 变量(var) & 常量(const)

    变量 声明变量格式: var var_name var_type 变量在声明时会自动初始化: 数字: 0 string: "" bool: false 引用类型: nil 结构体: ...

  2. Linux学习笔记-第19天 结束了。突然感觉配置一个服务好简单的样子

    课程结束了,这本书又过了一遍,感觉学习到了不少的新知识.虽然整个过程老师讲的有点仓促,但回头想想身处于这个知识大爆炸的时代,学习不单要追求知识面宽广,更需要注重学习的效率,某种角度来讲,这也是一种鞭策 ...

  3. WPF DataGrid 绑定数据及时更新的处理

    原文:WPF DataGrid 绑定数据及时更新的处理 默认情况下datagrid 绑定数据源后,在界面编辑某一列后,数据不会及时更新到内存对象中.如在同一行上有一个命令对来获取 当前选中行(内存对象 ...

  4. ASP.NET Core 集成测试中模拟登录用户的一种姿势

    不管哪种用户验证方式,最终都是在验证成功后设置 HttpContext.User ,后续处理环节通过 HttpContext.User 获取用户信息.如果能直接修改 HttpContext.User ...

  5. LeetCode 387: 字符串中的第一个唯一字符 First Unique Character in a String

    题目: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. Given a string, find the first non-repeating charact ...

  6. 【zabbix告警配置】zabbix服务配置邮件告警

    一.安装邮件服务 在zabbix_server服务端安装邮件和邮件发送服务,这里可以参考我另一篇邮件服务部署文章:https://www.cnblogs.com/HeiDi-BoKe/p/118833 ...

  7. Apollo的基本概念和集成实战

    基本概念 使用场景 是一个分布式的配置中心.适用于微服务: 核心功能 集中管理不同环境,不同集群的配置: 配置修改后可以实时推送到应用端: 具备规范的权限,流程治理特性: 开发技术 服务端使用spri ...

  8. json递归查询

    主体: class json_search(): '''递归查询依赖key''' def search_key(self,data,key): self.data = data self.key_va ...

  9. java基础(22):File、递归

    1. File 1.1 IO概述 回想之前写过的程序,数据都是在内存中,一旦程序运行结束,这些数据都没有了,等下次再想使用这些数据,可是已经没有了.那怎么办呢?能不能把运算完的数据都保存下来,下次程序 ...

  10. QT5.5+VS2013编译安装QtCharts (ZZ)

    环境 1.Windows 10 -x64: 2.MSVC 2013 -x64: 3.Qt5.5.1 -x86 and -x64. 编译过程 准备工作 1.安装ActivePerl 安装过程同一般软件安 ...