Make a Permutation! CodeForces - 864D 题意:给出n个数,用没出现过的1-n之内数字替换掉重复的部分,让该序列字典序最小。 思路:每次找出那个最小的没用数 L,(从前往后遍历)如果当前的数出现次数大于1次并且大于L,就替换他,然后更新一些标记数组。然后又有一种情况,L大于当前的数,但是这个...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5+100; int vis[maxn]; int a[maxn]; int used[maxn]; queue<int>q; int main(void) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); vis[a[i]]++; } for(int i=1;i<=n;...
Let's try to make a new task. Firstly we will use the following task. There arenpeople, sort them by their name. It is just an ordinary sorting problem, but we can make it more interesting by adding nondeterministic element. There arenpeople, each person will use either his/her first ...
#include<cstdio>#include<cstring>#include<vector>usingnamespacestd;intmain(){inta[210000],flag[210000],lag[210000],n;vector<int>vec;memset(flag,0,sizeof(flag));memset(lag,0,sizeof(lag));vec.clear();scanf("%d",&n);for(inti=0;i<n;i++){scanf("%d",&a[i]);flag[a[i]]++;}f...
change (replace)minimum number of elements in his array in such a way that his array becomes apermutation (i.e. each of the integers from1 tonwas encountered in his array exactly once). If there are multiple ways to do it he wants to find thelexicographically minimal permutation among ...
Codeforces Round #547 C. Polycarp Restores Permutation(二分枚举/数学+模拟) 题意: 有一个长度为N的序列p,该序列保证存在1~N每个值都存在,现在给出一个序列q,长度为N-1,表示序列p相邻两数之差,根据序列q输出序列p 题解: 一开始想复杂了,以为要找什么最大差值最小差值来扩展,又或者枚举的话可能因为不断...
First make a permutation that for each character store the nearest place it will go in the second string, then count the number of inversions of it using BIT or Trie or mergesort tree. For example : s=abcds=abcd and t=cdabt=cdab The permutation will be this: [3,4,1,2][3,4,...
position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters ins. Then you can permute the order of letters as you want. Permutation doesn't count as changes....
I don't know for sure how it's on AtCoder, but that's how I think it would be good on Codeforces. → Reply tempestDemise 2 years ago, # ^ | 0 What if you decide you can't make it to the contest, after having thought previously that you were going to be able to? Then...
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given the array aa consisting of nn elements and the integer k≤nk≤n. You want to obtain at least kk equal elements in the array aa. In one move, you can make one of...