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 ...
随机推荐
- [CTF]picoCTF-day1
Lets Warm Up If I told you a word started with 0x70 in hexadecimal, what would it start with in ASCI ...
- [Linux]Filesystem Hierarchy Standard/文件系统层次结构标准(FHS for Linux)
1 文件系统层次结构标准 本篇文章为维基百科中关于FHS的译文,原文见 wiki:https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard ...
- 被吐槽 GitHub仓 库太大,直接 600M 瘦身到 6M,这下舒服了
大家好,我是小富- 前言 忙里偷闲学习了点技术写了点demo代码,打算提交到我那 2000Star 的Github仓库上,居然发现有5个Issues,最近的一条日期已经是2022/8/1了,以前我还真 ...
- python:生成半年内的巡检日报execl
问题描述:使用脚本来生成半年内的数据,数据内容大概为每天的数据库巡检日报,临时抱佛脚.数据不可能是真实的,都是随机生成的,想要使用真实的数据后面直连操作系统或者数据库.后期可以慢慢实现自动化生成每天的 ...
- 【观察者设计模式详解】C/Java/JS/Go/Python/TS不同语言实现
简介 观察者模式(Observer Pattern)是一种行为型模式.它定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. 观察者模式使用三个类S ...
- blog图片资源
- Django框架——手写web框架、wsgiref模块、动静态网页、jinja2模块、主流web框架、Django简介、基本使用、app概念、目录结构、三板斧
web应用 '''通过浏览器访问的应用程序!!!''' 1.两种模式c/s b/s B/S:browser---------------->server 2.web应用程序的有点 2.1 只需要 ...
- Java并发(三)----创建线程的三种方式及查看进程线程
一.直接使用 Thread // 创建线程对象 Thread t = new Thread() { public void run() { // 要执行的任务 } }; // ...
- 获取电脑的网络连接状态(五)WebClient
网络连接判断,使用WebClient测试获取: 1 public static bool IsWebClientConnected() 2 { 3 try 4 { 5 using (var clien ...
- 2021-12-01:给定一个正数数组arr,代表每个人的体重。给定一个正数limit代表船的载重,所有船都是同样的载重量。 每个人的体重都一定不大于船的载重。 要求: 1, 可以1个人单独一搜船;
2021-12-01:给定一个正数数组arr,代表每个人的体重.给定一个正数limit代表船的载重,所有船都是同样的载重量. 每个人的体重都一定不大于船的载重. 要求: 1, 可以1个人单独一搜船: ...