Codeforces 1158C Permutation recovery】的更多相关文章

https://codeforces.com/contest/1158/problem/C 题目 已知 $p_1, p_2, \dots, p_n$ 是 $1$ 到 $n$ 的一个排列. 给出关于这个未知排列的一些描述:对于某些下标 $i$,$p_i$ 右边第一个大于 $p_i$ 的数的下标是 $R_i$ . $R_i = n + 1$ 意味着 $p_i$ 右边没有大于 $p_i$ 的数. 试问是否存在一个排列满足所有描述?若存在,任意给出一个这样的排列,若不存在,输出 -1 . Constra…
这道题其实只要解决了什么时候输出 -1 ,那么此题的构造方法也就解决了.首先我们可以观察这组 3 3 4 和 3 4 4 ,可以算出第二组是不成立的,在观察一组 2 3 4 5 和  3 2 4 5 ,第二组也是不成立的.我们将 i 和 a[ i ] 视为区间两端点,可以发现只有在任意一对区间不在端点处相交时才会出现 -1 .假设 a[ i-1 ] = x , a[ i ] = y , x < y ,那么可以得出 ans[ i - 1 ] < x , ans[ i ] < y .若 an…
Permutation Recovery Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 456    Accepted Submission(s): 316 Problem Description Professor Permula gave a number of permutations of the n integers 1,…
Permutation Recovery Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 451    Accepted Submission(s): 312 Problem Description Professor Permula gave a number of permutations of the n integers 1,…
题目传送门 /* 贪心:因为可以任意修改,所以答案是没有出现过的数字的个数 */ #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN]; bool vis[MAXN]; int main(void) //CodeForces 137B Permutation { int n; ) {…
题目链接:http://codeforces.com/problemset/problem/359/B 题目意思:给定n和k的值,需要构造一条长度为2n(每个元素取值范围只能是[1,2n])且元素各不相同的序列,这条序列符合等式. 首先非常感谢乌冬兄和syy的帮助!!尤其是乌冬兄. 刚开始做的时候完全没有思路,写出那条等式的展开式也没有发现规律.在他们的思维引导之下,我终于明白了这个问题其实可以简化为求一对数(假设为ai-1,ai)的差,这个差 = k 即可,但是k必须为负数!!!也就是ai-1…
首先看一下题目 B. Permutation Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation …
传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=2130 时间限制(普通/Java):2000MS/20000MS     内存限制:65536KByte 描述 Professor Permula gave a number of permutations of the n integers 1, 2, ... , n to her students. For each integer i,…
https://codeforces.com/problemset/problem/1033/C 一开始觉得自己的答案会TLE,但是吸取徐州赛区的经验去莽了一发. 其实因为下面这个公式是 $O(nlogn)$ 的,不是 $O(n²)$ ,所以这样做是可行的.学到了新的知识. $$\sum\limits_{i=1}^{n}\lfloor\frac{n}{i}\rfloor$$ PS:学会LaTeX啦! #include<bits/stdc++.h> using namespace std; #d…
https://codeforces.com/contest/1295/problem/E 建一颗线段树,叶子结点是花费从1到i所需要花费的前缀和,表示前i个元素全部移动到右边的花费,再维护区间最小值,然后从1到n-1扫一遍,对于第i个位置,找到数字i在序列中的位置 pos ,将区间1到pos-1加上数字i移动的花费,pos到n-1减去数字i移动的花费,因为位置大于等于i 的时候,不需要将数字i移动到右边,位置小于i 时,需要把数字i移动到左边,所以需要增加数字i的花费,结合线段树维护的是前缀和…
题目链接 link Solution 暴力一眼就可以看出来,枚举分界点,然后左右两边统计答案即可,但复杂度是我们无法接受的 然后我们看我们可以优化哪一部分 \(1^0\) 枚举:这部分没有办法优化 \(2^0\) 统计答案 这里我们看每一个位置上的数字在什么时候会有增加答案 当这种有的位置可以改变答案的时候,我们就要考虑贡献法 由题意,分割点位置不同时,每个位置对于该状态下答案是否贡献是不同的 "是否贡献"还是连续的,直接上线段树维护就好 (这里解释有点玄学,但是用贡献法还是不难理解的…
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2017-10-13       Latest Modification: 2018-02-28 #include<bits/stdc++.h> using namespace std; int a,b; int main() { cin>>a>>b; cout<<…
Building Permutation CodeForces - 285C Permutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number …
[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of…
Diverse Permutation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 483C Description Permutationp is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct positive i…
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) i…
B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/553/problem/B Description Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from…
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个.求序列. 思路:1~k+1.构造序列前段,之后直接输出剩下的数.前面的构造能够依据,两项差的绝对值为1~k构造. AC代码: #include <stdio.h> #include <string.h> int ans[200010]; bool vis[100010]; i…
Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 691D Description You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj). At each step you can choose a…
D. Make a Permutation! time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Recently Ivan learned…
Codeforces 1091D New Year and the Permutation Concatenation https://codeforces.com/contest/1091/problem/D 题目: Let n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence p. For…
D. Swaps in Permutation 题目连接: http://www.codeforces.com/contest/691/problem/D Description You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj). At each step you can choose a pair from the given positions and swap…
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 序列中的数无论怎么改,都不会改变与绝对值最大的数的逆序对的数量 所以从绝对值最大的数开始,决定它的正负 若这个序列中没有重复的最大值 若i是正数,与右边比他小的形成逆序对 若i是负数,与左边比他小的形成逆序对 所以两边取较小的 若序列中出现重复的最大值 那么最优解的最大值一定是 先是若干个负数,然…
A. Nicholas and Permutation 题目连接: http://www.codeforces.com/contest/676/problem/A Description Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum eleme…
Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/482/problem/A Description Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct posi…
A. Prime Permutation 题目连接: http://www.codeforces.com/contest/123/problem/A Description You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from…
http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consist…
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /************************************************ Author :Running_Time Created Time :2015-8-2 9:20:01 File Name :B.cpp **************************************…
http://codeforces.com/contest/691/problem/D D. Swaps in Permutation   You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj). At each step you can choose a pair from the given positions and swap the numbers in that…
Codeforces 785 E. Anton and Permutation 题目大意:给出n,q.n代表有一个元素从1到n的数组(对应索引1~n),q表示有q个查询.每次查询给出两个数l,r,要求将索引为l,r的两个数交换位置,并给出交换后数组中的逆序对数. 思路:此题用到了分块的思想,即将这组数分为bsz块,在每一块上建Fenwick树,对于每次查询,只需要处理l,r中间的块和l,r所在块受影响的部分.具体实现见代码及注释. #include<iostream> #include<…