BZOJ 2093: [Poi2010]Frog
Description
从一个点到达与他距离第 \(k\) 小的点,问从每个点跳 \(m\) 次到达那个点.
Sol
队列+倍增.
保持队列里的元素个数为 \(k\) ,从前往后扫不难发现左右端点都是单调的.
求跳 \(m\) 次就是倍增了,滚一下数组.
Code
/**************************************************************
Problem: 2093
User: BeiYu
Language: C++
Result: Accepted
Time:7256 ms
Memory:20832 kb
****************************************************************/ #include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int N = 1e6+50;
const int M = 65; LL n,k,m,l,r,lm;
LL a[N],pow2[M];
int f[2][N],g[N]; inline LL in(LL x=0,char ch=getchar()) { while(ch>'9' || ch<'0') ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x; }
int main() {
n=in(),k=in(),m=in(),lm=log2(m)+1;
for(int i=1;i<=n;i++) a[i]=in(); l=1,r=k+1; for(int i=1;i<=n;i++) {
while(r<n && a[r+1]-a[i] < a[i]-a[l]) r++,l++;
f[0][i]=(a[r]-a[i] > a[i]-a[l] ? r : l);
} pow2[0]=1;for(int i=1;i<=lm;i++) pow2[i]=pow2[i-1]<<1;
if(m&1) for(int i=1;i<=n;i++) g[i]=f[0][i];
else for(int i=1;i<=n;i++) g[i]=i;
r=1;
for(int j=1;j<=lm;j++) {
for(int i=1;i<=n;i++) f[r][i]=f[r^1][f[r^1][i]];
if(m&pow2[j]) for(int i=1;i<=n;i++) g[i]=f[r][g[i]];
r^=1;
}
for(int i=1;i<=n;i++) printf("%d%c",g[i]," \n"[i==n]);
return 0;
}
BZOJ 2093: [Poi2010]Frog的更多相关文章
- bzoj 2093 [Poi2010]Frog——滑动窗口
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2093 找第k近的可以用一个含k个元素的滑动窗口来实现. 卡空间也还行,但卡时间.不要预处理倍 ...
- bzoj2093: [Poi2010]Frog(单调队列,倍增)
2093: [Poi2010]Frog Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 568 Solved: 186[Submit][Status] ...
- bzoj 2093 [ Poi 2010 ] Frog —— 滑动窗口 + 倍增
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2093 先处理出每个点第一次会跳到哪里: 开一个长度为 K+1 的窗口(因为第一近的实际是自己 ...
- BZOJ 2080: [Poi2010]Railway 双栈排序
2080: [Poi2010]Railway Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 140 Solved: 35[Submit][Statu ...
- BZOJ 2096: [Poi2010]Pilots( set )
用个set维护就可以水过去...O(NlogN) 应该可以用单调队列O(N).... --------------------------------------------------------- ...
- BZOJ 2096([Poi2010]Pilots-单调队列-差值)
2096: [Poi2010]Pilots Time Limit: 30 Sec Memory Limit: 162 MB Submit: 190 Solved: 97 [ Submit][ ...
- bzoj 2095: [Poi2010]Bridges [混合图欧拉回路]
2095: [Poi2010]Bridges 二分答案,混合图欧拉路判定 一开始想了一个上下界网络流模型,然后发现不用上下界网络流也可以 对于无向边,强制从\(u \rightarrow v\),计算 ...
- BZOJ 2084: [Poi2010]Antisymmetry [Manacher]
2084: [Poi2010]Antisymmetry Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 609 Solved: 387[Submit] ...
- BZOJ 2083: [Poi2010]Intelligence test [vector+二分]
2083: [Poi2010]Intelligence test Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 469 Solved: 227[Su ...
随机推荐
- [LeetCode] Pacific Atlantic Water Flow 太平洋大西洋水流
Given an m x n matrix of non-negative integers representing the height of each unit cell in a contin ...
- [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- [LeetCode] Palindrome Partitioning 拆分回文串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- [LeetCode] Two Sum 两数之和
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- csv表格处理(上)-- JS 与 PHP 协作导入导出
CSV简介 在开发后台管理系统的时候,几乎无可避免的会遇到需要导入导出Excel表格的需求.csv也是表格的一种,其中文名为“逗号分隔符文件”.在Excel中打开如下图左边所示,在记事本打开如下图右边 ...
- NFS简单使用
NFS网络文件系统(Network File System),由Sun公司开发,从名字上就能够知道这个服务是通过网络的方式来共享文件系统,目前RHEL 6上使用的版本为NFSv4,提供有状态的连接,追 ...
- 使用Hibernate的 isNotEmpty( ) 方法 报错: No result defined .... and result dataAccessFailure
数据访问失败 出错代码: cardy.add(Restrictions.isNotEmpty("grade.cardtype.cardtype")); try...catch之后发 ...
- MATLAB的三维散点图
MATLAB中三维散点图函数为scatter3(x,y,z) 三维火柴图为stem3(x,y,z)
- 自己对js对原型链的理解
js对象分为2种 函数对象和普通对象 函数对象 比如 function Show(){}var x=function Show2(){}var b=new Function("show3&q ...
- Chrome 开发工具之Console
前段时间看git的相关,记的笔记也大致写到了博客上,还有些因为运用不熟,或者还有一些疑惑点,暂时也不做过多纠缠,之后在实践中多运用得出结论再整理分享吧. 工欲善其事,必先利其器.要想做好前端的工作,也 ...