当前位置: 首页> 游戏> 评测 > 六安人论坛招聘网_武汉网站排名提升_今日国内新闻热点_今日油价92汽油价格表

六安人论坛招聘网_武汉网站排名提升_今日国内新闻热点_今日油价92汽油价格表

时间:2025/7/28 22:37:39来源:https://blog.csdn.net/weixin_73596091/article/details/144566334 浏览次数:0次
六安人论坛招聘网_武汉网站排名提升_今日国内新闻热点_今日油价92汽油价格表

D. Harder Problem

Given a sequence of positive integers, a positive integer is called a mode of the sequence if it occurs the maximum number of times that any positive integer occurs. For example, the mode of [ 2 , 2 , 3 ] [2,2,3] [2,2,3] is 2 2 2. Any of 9 9 9, 8 8 8, or 7 7 7 can be considered to be a mode of the sequence [ 9 , 9 , 8 , 8 , 7 , 7 ] [9,9,8,8,7,7] [9,9,8,8,7,7].

You gave UFO an array a a a of length n n n. To thank you, UFO decides to construct another array b b b of length n n n such that a i a_i ai is a mode of the sequence [ b 1 , b 2 , … , b i ] [b_1, b_2, \ldots, b_i] [b1,b2,,bi] for all 1 ≤ i ≤ n 1 \leq i \leq n 1in.

However, UFO doesn’t know how to construct array b b b, so you must help her. Note that 1 ≤ b i ≤ n 1 \leq b_i \leq n 1bin must hold for your array for all 1 ≤ i ≤ n 1 \leq i \leq n 1in.

Input

The first line contains t t t ( 1 ≤ t ≤ 1 0 4 1 \leq t \leq 10^4 1t104) — the number of test cases.

The first line of each test case contains an integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \leq n \leq 2 \cdot 10^5 1n2105) — the length of a a a.

The following line of each test case contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an ( 1 ≤ a i ≤ n 1 \leq a_i \leq n 1ain).

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each test case, output n n n numbers b 1 , b 2 , … , b n b_1, b_2, \ldots, b_n b1,b2,,bn ( 1 ≤ b i ≤ n 1 \leq b_i \leq n 1bin) on a new line. It can be shown that b b b can always be constructed. If there are multiple possible arrays, you may print any.

Example
input
4
2
1 2
4
1 1 1 2
8
4 5 5 5 1 1 2 1
10
1 1 2 2 1 1 3 3 1 1
out
1 2
1 1 2 2
4 5 5 1 1 2 2 3
1 8 2 2 1 3 3 9 1 1

Note

Let’s verify the correctness for our sample output in test case 2 2 2.

  • At i = 1 i = 1 i=1, 1 1 1 is the only possible mode of [ 1 ] [1] [1].
  • At i = 2 i = 2 i=2, 1 1 1 is the only possible mode of [ 1 , 1 ] [1, 1] [1,1].
  • At i = 3 i = 3 i=3, 1 1 1 is the only possible mode of [ 1 , 1 , 2 ] [1, 1, 2] [1,1,2].
  • At i = 4 i = 4 i=4, 1 1 1 or 2 2 2 are both modes of [ 1 , 1 , 2 , 2 ] [1, 1, 2, 2] [1,1,2,2]. Since a i = 2 a_i = 2 ai=2, this array is valid.

题目大意:要构造出一个b数组,令其满足每个a[i] 在[b1,b2,b3,…,bi]中可以做模,那么得到的这个b数组则是正确的。

思路:我们有n个位置放数,那我们就按照123…n这种情况放数,这样每个数只出现一次,这样每一个数都可以作为模数,但是,要注意数出现的顺序,所以我们出现一个新的就输出当前这个数,然后遍历1~n看哪个数还没出现过,没出现的则输出。

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;const int N = 2e5+10;
int a[N];
int vis[N];void solve(){memset(vis,0,sizeof(vis));int n;scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);if(vis[a[i]] == 0){vis[a[i]] = 1;printf("%d ", a[i]);}}for (int i = 1; i <= n; i++){if(vis[i] == 0){printf("%d ",i);}}return ;
}int main(){int t;scanf("%d", &t);while(t--){solve();}
}
关键字:六安人论坛招聘网_武汉网站排名提升_今日国内新闻热点_今日油价92汽油价格表

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: