当前位置:网站首页>Modify array (and search set)
Modify array (and search set)
2022-04-23 01:25:00 【OldLeft】
Given a length of N Array of A=[A1,A2,⋅⋅⋅AN], There may be repeated integers in the array .
Now Xiaoming will change it to an array without repeating integers as follows .
Xiao Ming will revise in turn A2,A3,⋅⋅⋅,AN.
When modifying Ai when , Xiao Ming will check Ai Whether in A1∼Ai−1 There has been .
If there has been , Then Xiao Ming will give Ai add 1; If the new Ai Still before , Xiaoming will continue to give Ai Add 1, until Ai Not in the A1∼Ai−1 There has been .
When AN After the above modifications , obviously A There are no duplicate integers in the array .
Now let's give the initial A Array , Please work out the final A Array
Input format
The first line contains an integer N.
The second line contains N It's an integer A1,A2,⋅⋅⋅,AN.
Output format
Output N It's an integer , In turn is the final A1,A2,⋅⋅⋅,AN.
Data range
1≤N≤10^5,
1≤Ai≤10^6
sample input :
5
2 1 1 3 4
sample output :
2 1 3 4 5
Answer key :
Union checking set , The ancestors of initializing numbers at the beginning are themselves , If the output is too , Then the number of ancestors shall be added to his original ancestors 1
#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
int father[1000006];
int findfather(int x){
if(x!=father[x]) father[x]=findfather(father[x]);
return father[x];
}
int main(){
cin>>n;
for(int i=1;i<1e6+2;i++){
father[i]=i;
}
for(int i=0;i<n;i++){
int x;
cin>>x;// use scanf Better, faster ,cin It's easy to time out
x=findfather(x);
cout<<x<<" ";
father[x]=x+1;
}
return 0;
}
版权声明
本文为[OldLeft]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230120462494.html
边栏推荐
- Small example of gin - get request 1-handle handles get requests
- Optical cat super account password, reset optical cat to obtain super account password
- Soatest preliminary understanding
- Detailed explanation of Milvus 2.0 quality assurance system
- New functions of ai2022, introduction to new functions of illustrator 2022
- Interview eight part essay (disorderly order, no classification)
- GBase 8s查询处理和优化
- Gbase 8s group by function introduction
- Gbase 8s检查点简介
- Gbase 8s存儲結構簡介及空間管理
猜你喜欢

Huawei CDN is fast everywhere

Common problems and solutions of crashsight access reporting

From thinking to practice, digital transformation is the successful path of it operation

In the second half of the smart watch, opportunities and challenges coexist

清研环境深交所上市:年营收1.8亿 市值41亿

engine. Post() handles post requests

引爆炸弹(DFS)
再谈被动安全 教你看懂中保研碰撞测试的评级报告

Abused "architect"!
![[course summary] Hello harmonyos series of courses, take you to zero foundation introduction](/img/65/96ff0b526cd8f507df82c80a47a35e.jpg)
[course summary] Hello harmonyos series of courses, take you to zero foundation introduction
随机推荐
Get rid of the "small workshop" of AI production: how to build a cloud native AI platform based on kubernetes
Interview eight part essay (disorderly order, no classification)
Here's the point. Have you mastered the most complete Web3 jargon guide?
Error: permissionerror: [winerror 32] this file is in use by another program and cannot be accessed by the process. Solution of "+ file path"
Unity combines itextsharp to generate PDF preparation DLL
清研环境深交所上市:年营收1.8亿 市值41亿
光猫超级帐号密码,重置光猫获取超级帐号密码
Unity结合iTextSharp生成PDF 准备dll
Interface automation session authentication solution
Cai Guoqiang's fireworks NFT debut is as wonderful as fireworks during the day
The code bought from the salted fish | SSM hotel room management system | whether the purchased source code can really be used | confusion from the programmer | Yu Nianyu Hui | Wu Minghui, dachou Vill
Gbase 8s 共享内存段删除
API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
[JS] realize the export of PDF from the specified area of the web page
无关联进程间通信 —— 命名管道的创建和使用
Gbase 8s存儲結構簡介及空間管理
Vscode + PHP debug + namespace guidelines
8GBs communication between client and server
Introduction à la structure de stockage de gbase 8S et à la gestion de l'espace
代码实现发邮件---sendemails