题意

给定一个 \(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的更多相关文章

  1. [atARC114F]Permutation Division

    由于是排列,即任意两个数字都各不相同,因此字典序最大的$q_{i}$就是将每一段的第一个数从大到小排序 接下来,考虑第一个元素,也就是每一段开头的最大值,分类讨论: 1.当$p_{1}\le k$时, ...

  2. python from __future__ import division

    1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...

  3. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  4. [LeetCode] Evaluate Division 求除法表达式的值

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

  5. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  6. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  7. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  8. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  9. 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 ...

  10. 关于分工的思考 (Thoughts on Division of Labor)

    Did you ever have the feeling that adding people doesn't help in software development? Did you ever ...

随机推荐

  1. Python最详细的Excel操作方式,

    为 什么要学会使用Excel在机器学习模型的建立中,不得不借助于Excel强大的统计分析能力,这个时候就牵涉到了如何将python直接处理得到的数据存入excel表格当中以及获取表格的数据进行分析,简 ...

  2. [Java EE] java.net.SocketException: Connection reset【解决中】

    1 错误描述 6:44:33.112] [DEBUG] [http-nio-9527-exec-3] [HttpClientUtil] http post url:http://bdp-gateway ...

  3. [数据库]mysql/mysqldump命令帮助说明

    1 mysql [root@test ~]# mysql --help mysql Ver 14.14 Distrib 5.7.24-27, for Linux (x86_64) using 6.0 ...

  4. Java 8新特性之 Optional 类

    前言 java.util.Optional 是java8中引进的一个新的类,我们通过Optional类的源码可以看到,该方法的作用可以对可能缺失的值进行建模,而不是直接将null赋值给变量. Opti ...

  5. Python开发遇到的一些问题

    1.SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.Try usin ...

  6. 4.测试类mapper报错

    1.总结:前几天还有今天一直在弄测试类报错的原因,想着项目是一个大整体,写一个mappe测试类,测试一个mapper,这样后面不会出错: 但是在测试mapper的时候一直,出现mapper值为空的异常 ...

  7. list列表和tuple、条件判断、循环、dict和set、调用函数、定义函数

    1.list列表是有序的可变的列表,可以进通过append()方法末尾添加,通过pop删除末尾以及根据索引pop(i)来删除指定索引对应的元素 通过给指定的列表元素赋值更改元素值,通过列表的索引查看元 ...

  8. 【Diary】CSP-S 2020 游记

    一年 好快 从三百多天倒计时 一点一点掂着 又回来了 但是时间永远不会等待你. --??? CSP-J1/S1 CSP-J1/S1 Day0 请了一上午假. 这段时间都在摸鱼,作业没写( 多备赛一个上 ...

  9. vivo全球商城:电商交易平台设计

    作者:vivo 官网商城开发团队 - Cheng Kun.Liu Wei 本文介绍了交易平台的设计理念和关键技术方案,以及实践过程中的思考与挑战. 点击查阅:<vivo 全球商城>系列文章 ...

  10. R的基本用法2

    title: "Lectures" author: '01' date: "2022-09-23" output: pdf_document knitr::op ...