CF1685E.The Ultimate LIS Problem
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
It turns out that this is exactly the 100-th problem of mine that appears in some programming competition. So it has to be special! And what can be more special than another problem about LIS...
You are given a permutation p1,p2,…,p2n+1 of integers from 1 to 2n+1. You will have to process q updates, where the i-th update consists in swapping pui,pvi.
After each update, find any cyclic shift of p with LIS≤n, or determine that there is no such shift. (Refer to the output section for details).
Here LIS(a) denotes the length of longest strictly increasing subsequence of a.
Hacks are disabled in this problem. Don't ask why.
事实证明,这恰好是我出现在某场编程竞赛中的第 100 个题目。因此它必须很特别!而还有什么能比另一个关于最长递增子序列(LIS)的题目更特别呢?
你将得到一个由整数 1 到 2n+1 构成的排列 p1,p2,…,p2n+1。你需要处理 q 次更新,其中第 i 次更新交换 pui 与 pvi。
每次更新后,请找出 p 的任意一个循环移位,使得其最长严格递增子序列(LIS)长度不超过 n;若不存在这样的循环移位,则判定其不存在。(具体输出格式详见“输出”部分)
此处 LIS(a) 表示序列 a 的最长严格递增子序列 的长度。
本题禁用 Hack 功能。别问为什么。
输入格式
The first line of the input contains two integers n,q (2≤n≤105, 1≤q≤105).
The second line of the input contains 2n+1 integers p1,p2,…,p2n+1 (1≤pi≤2n+1, all pi are distinct) — the elements of p.
The i-th of the next q lines contains two integers ui,vi (1≤ui,vi≤2n+1, ui=vi) — indicating that you have to swap elements pui,pvi in the i-th update.
输入的第一行包含两个整数 n,q(2≤n≤105,1≤q≤105)。
输入的第二行包含 2n+1 个整数 p1,p2,…,p2n+1(1≤pi≤2n+1,且所有 pi 互不相同)—— 即排列 p 的元素。
接下来的 q 行中,第 i 行包含两个整数 ui,vi(1≤ui,vi≤2n+1,且 ui=vi),表示在第 i 次更新中需交换元素 pui 与 pvi。
输出格式
After each update, output any k (0≤k≤2n), such that the length of the longest increasing subsequence of (pk+1,pk+2,…,p2n+1,p1,…,pk) doesn't exceed n, or −1, if there is no such k.
每次更新后,输出任意一个 k(0≤k≤2n),使得序列 (pk+1,pk+2,…,p2n+1,p1,…,pk) 的最长递增子序列长度不超过 n;若不存在满足条件的 k,则输出 −1。
输入输出样例
输入#1
2 6 1 2 3 4 5 1 5 1 5 4 5 5 4 1 4 2 5
输出#1
-1 -1 2 -1 4 0
说明/提示
After the first update, our permutation becomes (5,2,3,4,1). We can show that all its cyclic shifts have LIS≥3.
After the second update, our permutation becomes (1,2,3,4,5). We can show that all its cyclic shifts have LIS≥3.
After the third update, our permutation becomes (1,2,3,5,4). Its shift by 2 is (3,5,4,1,2), and its LIS=2.
After the fourth update, our permutation becomes (1,2,3,4,5). We can show that all its cyclic shifts have LIS≥3.
After the fifth update, our permutation becomes (4,2,3,1,5). Its shift by 4 is (5,4,2,3,1), and its LIS=2.
After the fifth update, our permutation becomes (4,5,3,1,2). Its shift by 0 is (4,5,3,1,2), and its LIS=2.
第一次更新后,我们的排列变为 (5,2,3,4,1)。我们可以证明其所有循环移位的最长递增子序列长度(LIS)均满足 LIS≥3。
第二次更新后,我们的排列变为 (1,2,3,4,5)。我们可以证明其所有循环移位的 LIS≥3。
第三次更新后,我们的排列变为 (1,2,3,5,4)。其向右循环移位 2 位后的结果为 (3,5,4,1,2),且其 LIS=2。
第四次更新后,我们的排列变为 (1,2,3,4,5)。我们可以证明其所有循环移位的 LIS≥3。
第五次更新后,我们的排列变为 (4,2,3,1,5)。其向右循环移位 4 位后的结果为 (5,4,2,3,1),且其 LIS=2。
第五次更新后,我们的排列变为 (4,5,3,1,2)。其向右循环移位 0 位后的结果为 (4,5,3,1,2),且其 LIS=2。
输入解题思路,AI测评打分。不知道怎么写?