CodeForces 1187D Subarray Sorting】的更多相关文章

Problem You are given an array \(a_1\),\(a_2\),-,\(a_n\) and an array \(b_1\),\(b_2\),-,\(b_n\). For one operation you can sort in non-decreasing order any subarray \(a[l-r]\) of the array \(a\). For example, if \(a=[4,2,2,1,3,1]\) and you choose sub…
Educational Codeforces Round 67 D. Subarray Sorting 传送门 题意: 给出两个数组\(a,b\),现在可以对\(a\)数组进行任意次排序,问最后能否得到\(b\)数组. \(n\leq 3*10^5,a\leq n.\) 思路: 首先注意到任意次排序可以等价于任意次交换两个相邻的数,当且仅当前一个数不小于后面一个数. 我一开始想的是按权值从小到大来构造,但最终发现这条路走不通. 正解就是比较直接的思路,按位置一个一个来匹配. 对于一个\(b_i\…
http://codeforces.com/contest/876/problem/D D. Sorting the Coins time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Recently, Dima met with Sasha in a philatelic store, and since then they are…
题目链接: http://www.codeforces.com/contest/606/problem/C 一道dp问题,我们可以考虑什么情况下移动,才能移动最少.很明显,除去需要移动的车,剩下的车,一定是相差为1的递增序列,而且这个序列一定也是最长的,例如4 1 2 5 3, 4 5是需要移动的,不移动的序列是1 2 3,所以我们只要求出这一最长的递增序列,用n去减就可以了. dp[i]是以i为结尾,最长的递增序列,所以dp[i] = dp[i-1]+1,求最大即为所求结果. #include…
911E - Stack Sorting 思路: 用栈来模拟,能pop就pop,记下一个需要pop的数为temp,那么如果栈非空,栈顶肯定大于temp,那么加入栈 栈顶值-1 到 temp 的值,否则加入栈 n 到 temp 的值,如果需要加入的数之前已经出现过,答案则不存在. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define meme(a,b)…
C. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are d…
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 10…
题目链接:http://codeforces.com/contest/876/problem/D 题解:一道简单的类似模拟的题目.其实就是看右边连出来有多少连续不需要换的假设位置为pos只要找pos-1左边一共有多少x就行(x是什么看一下样例) 第一个是正常解法第二个是用线段树写的,其实正常写就是模拟一下就好 #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #i…
思路:首先 他是对1到k 元素做一次变换,然后对2到k+1个元素做一次变化....依次做完. 如果我们对1到k个元素做完一次变换后,把整个数组循环左移一个.那么第二次还是对1 到 k个元素做和第一次一样的变换,再左移,再对1 到 k个元素做和第一次一样的变换,依次做完n-k+1即可. 假设题目要求的变换为C    循环左移变换为P.那么对于每次查询 相当于做  n-k+1  (CP) 变换.最后把答案再向右移动n-k+1  回到原来位置即可. 那么问题就解决了   效率    每次查询n log…
我们肯定要一大一小间隔开来所以 把式子拆出来就是类似这样的形式 s1 - 2 * s2 + 2 * s3 + ...... + sn 然后把状态开成四个, 分别表示在顶部, 在底部, 在顶部到底部的中间, 在底部到顶部的中间. 反思一下为什么没写出来:我在考虑的时候 |s2 - s1| + |s3 - s2| + |s4 + s3| ,,, 我在想怎么把si 和 si + 1的大小关系的问题, 其实不用考虑, 因为我们求的是最大值, 所以对答案是没有影响的. #include<bits/stdc…