Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int maxn = 2000000 + 100;
- int n;
- int fa[maxn], num[maxn];
- void init() {
- for (int i = 1; i < maxn; ++i) {
- fa[i] = i;
- }
- }
- int findF(int x) {
- return fa[x] == x ? x : fa[x] = findF(fa[x]);
- }
- void union_(int x, int y) {
- fa[findF(x)] = findF(y);
- }
- void del(int x) {
- union_(x, x + 1);
- }
- int main() {
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif // ExRoc
- ios::sync_with_stdio(false);
- init();
- cin >> n;
- for (int i = 1; i <= n; ++i) {
- cin >> num[i];
- num[i] = findF(num[i]);
- del(num[i]);
- }
- for (int i = 1; i <= n; ++i) {
- cout << num[i] << " ";
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement