ARC114F Permutation Division
题意
给定一个 \(1 \sim N\) 的排列,Alice 把它划分成 \(k\) 段,Bob 把这 \(k\) 段任意排列。Alice 想让字典序最小,Bob 想让字典序最大。请问最后的排列。
数据范围: \(1\le k\le N\le 2 \times 10^5\)。
题解
首先 Bob 的排序只取决于每个段第一个数的大小。字典序不会变小,所以考虑最大化最长公共前缀长度。假设公共前缀长度为某个数是合法的,那么需要满足前面的划分是一个下降子序列,并且后面不能有比最后一个段的开头还大的数作为段落开头。那么考虑枚举最后一个段的开头 \(x\),计算一下前面包含序列第一个数的最长下降子序列长度,可以计算出后面至少要划分出 \(t\) 段,于是可以二分出一个位置使得这个位置后面恰好有 \(t\) 个小于 \(x\) 的元素。那么这个位置前面就是最长公共前缀。找到最长公共前缀长度以后,后面刚好有 \(t\) 个元素可以作为开头,按照他们划分段,然后排序即可。
ARC114F Permutation Division的更多相关文章
- [atARC114F]Permutation Division
由于是排列,即任意两个数字都各不相同,因此字典序最大的$q_{i}$就是将每一段的第一个数从大到小排序 接下来,考虑第一个元素,也就是每一段开头的最大值,分类讨论: 1.当$p_{1}\le k$时, ...
- python from __future__ import division
1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Evaluate Division 求除法表达式的值
Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Next Permutation 下一个排列
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- Leetcode 60. Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- 关于分工的思考 (Thoughts on Division of Labor)
Did you ever have the feeling that adding people doesn't help in software development? Did you ever ...
随机推荐
- 遗传算法(启发式算法)—R实现
遗传算法 遗传算法(Genetic Algorithm,GA)最早是由美国的 John holland于20世纪70年代提出,该算法是根据大自然中生物体进化规律而设计提出的.是模拟达尔文生物进化论的自 ...
- 在k8s安装CICD-devtron
在k8s安装CICD-devtron 先前条件 <kubernetes(k8s) 存储动态挂载>参考我之前的文档进行部署https://www.oiox.cn/index.php/arch ...
- Centos9网卡配置
Centos9 网卡配置文件已修改,如下 [root@bogon ~]# cat /etc/NetworkManager/system-connections/ens18.nmconnection [ ...
- Redis 数据类型 Stream
Redis 数据类型 Stream Redis 常用命令,思维导图 >>> Redis Stream 是 Redis 5.0 版本新增加的数据结构. Redis Stream 主要用 ...
- vivo全球商城:电商交易平台设计
作者:vivo 官网商城开发团队 - Cheng Kun.Liu Wei 本文介绍了交易平台的设计理念和关键技术方案,以及实践过程中的思考与挑战. 点击查阅:<vivo 全球商城>系列文章 ...
- v-if与v-for的优先级
在Vue2中 v-for的优先级要高于v-if 在Vue3中 v-if 的优先级要高于v-for
- Python实现网络工具
使用python编写网络工具 基础内容 介绍基本的网络编程 Socket编程 Socket又称"套接字",应用程序通常通过"套接字"向网络发出请求或者应答网络请 ...
- 基础常用API总结2
String java.lang包下 返回值类型 方法 功能 boolean matches(String regex) 如果匹配当前字符串中regex(正则表达式)所表示的字符,如果有返回ture没 ...
- 网络编程之java简易聊天室实现
最近浅学习了一些关于网络编程方面的知识,视频是跟着狂神学习的,可能学习的不是很深 说到网络,相信大家都对TCP.UDP和HTTP协议这些都不是很陌生,学习这部分应该先对端口.Ip地址这些基础知识有一定 ...
- DataX更换python3,File “datax.py“, line 114 print readerRef
datax 报错 File "datax.py", line 114 print readerRef 报错: File "datax.py", line 114 ...