Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, s; int niz[maxn], sol[maxn], saz[maxn]; vector<pair<int, int> > graph[maxn]; bool bio[maxn], bio2[maxn]; vector<int> sa; vector<vector<int> > al; vector<int> ac[maxn]; void dfs(int node) { bio2[node] = true; while (!graph[node].empty())...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') neg = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x * neg; } inline int qpow(int x, int e, int _MOD) { int ans = 1; ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int N, S; int A[200020], B[200020]; vector<int> vx; int pp[200020]; int Find(int x) { return pp[x] == x ? x : pp[x] = Find(pp[x]); } vector<int> vs[2][200020]; int nxt[200020]; int main() { scanf("%d%d", &N, &S); for (int i = 1; i <= N; i++) scanf("%d", A + i); for (i...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[200000]; int nxt[200000]; bool v[200000]; vector<int> cycle; void dfs(int now) { v[now] = true; while (nxt[now] < adj[now].size()) { cycle.push_back(adj[now][nxt[now]].second); nxt[now]++; dfs(adj[now][nxt[now] - 1].first); } } ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int M = 0, fst[666666], vb[666666], nxt[666666], vc[666666]; void ad_de(int a, int b, int c) { ++M; nxt[M] = fst[a]; fst[a] = M; vb[M] = b; vc[M] = c; } void adde(int a, int b, int c) { ad_de(a, b, c); ad_de(b, a, c); } map<int, int> vis; int n, s, a[666666], ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct A { int x, id; } a[N]; bool cmp(A x, A y) { return x.x < y.x; } struct Edge { int to, next; } edge[N]; int n, s, head[N], num; void add_edge(int a, int b) { edge[++num] = (Edge){b, head[a]}, head[a] = num; } int f[N], ne[N], cc[N], c0, c1; b...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200600; int n, S; int a[N]; int b[N]; int xs[N]; int k; vector<int> g[N]; int m; vector<int> cycles[N]; int p[N]; bool used[N]; void dfs(int v) { while (!g[v].empty()) { int id = g[v].back(); g[v].pop_back(); dfs(a[id]); cycles[m].push_back(i...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long inf = 4e18; const long long maxn = 2e5 + 10; const long long mod = 1e9 + 7; long long a[maxn], b[maxn], f[maxn]; vector<long long> v[maxn]; map<long long, long long> mp; vector<vector<long long> > ans; vector<long long> vec; bool mark[maxn]; int main() { l...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 10; long long a[maxn], b[maxn], f[maxn]; vector<long long> v[maxn]; map<long long, long long> mp; vector<vector<long long> > ans; vector<long long> vec; bool mark[maxn]; long long par[maxn]; long long Find(long long x) { return (par[x] < 0 ? x...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; vector<bool> vis; vector<pair<long long, long long>> eulerWalk( vector<vector<pair<long long, long long>>>& gr, vector<long long>& eu, int src, vector<long long>& D, vector<long long>& its) { vector<pair<long long, long long>> ret, s = ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 10; long long a[maxn], b[maxn], f[maxn]; vector<long long> v[maxn]; map<long long, long long> mp; vector<vector<long long> > ans; vector<long long> vec; bool mark[maxn]; long long par[maxn]; long long Find(long long x) { return (par[x] < 0 ? x...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k, tot, x, ans, a[1000000], b[1000000], f[1000000], ed[1000000], nt[1000000], nm[1000000], ss[1000000]; map<int, int> mp, rw; bool v[1000000]; int gf(int x) { if (f[x] == x) return x; f[x] = gf(f[x]); return f[x]; } int main() { scanf("%d %d", &n, &k); ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int Maxn = 200005; int n, s, ct, tmp_n, ans_ct, a[Maxn], b[Maxn], fa[Maxn], pos[Maxn], ord[Maxn], bel[Maxn], Pos[Maxn]; vector<int> spec, Ve[Maxn]; bool vis[Maxn]; void dfs(int u) { if (vis[u]) return; bel[u] = ct, vis[u] = true, dfs(ord[u]); } void dfs2(int u...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; int n, limit; int nxt[N], lab[N], flag[N]; pair<int, int> a[N]; vector<int> ans1, ans2; vector<vector<int> > ans3; vector<pair<int, int> > v; int root(int u) { if (lab[u] < 0) return u; return lab[u] = root(lab[u]); } void join(int u, int v) { ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
java
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.StringTokenizer; import java.util.Tre...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct A { int x, id; } a[N]; bool cmp(A x, A y) { return x.x < y.x; } struct Edge { int to, next, id; } edge[N]; int n, s, head[N], num; void add_edge(int a, int b, int id) { edge[++num] = (Edge){b, head[a], id}, head[a] = num; } int f[N], ne[N]...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using std::lower_bound; using std::max; using std::min; using std::random_shuffle; using std::reverse; using std::sort; using std::swap; using std::unique; using std::upper_bound; using std::vector; void open(const char *s) {} int rd() { int s = 0, c, b = 0; while (((c = getchar()) < '0' ||...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using std::vector; const int N = 300005; int a[N], b[N], nt[N], t[N], n, cnt, now, s; vector<int> ans[N]; int nxt(int x) { while (nt[x] < t[x + 1] && a[nt[x]] == x) nt[x]++; return nt[x]; } void dfs(int x) { if (nxt(x) < t[x + 1]) { ans[now].push_back(nt[x]); dfs(a[nt[x]++]); } ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<doub...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxN = 202000; int n, S, ufs[maxN], Id[maxN], vis[maxN]; pair<int, int> A[maxN]; vector<int> Ring[maxN]; int find(int x); void dfs(int rcnt, int u); int main() { scanf("%d%d", &n, &S); for (int i = 1; i <= n; i++) scanf("%d", &A[i].first), A[i].second = uf...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int MAX_N = 200000; int v[1 + MAX_N], poz[1 + MAX_N], sorted[1 + MAX_N]; bool cmp(int a, int b) { return v[a] < v[b]; } std::vector<int> src[1 + MAX_N], target[1 + MAX_N]; void normalize(int n) { std::sort(poz + 1, poz + 1 + n, cmp); int last = v[poz[1]], j = 1; for (int i = 1; i <=...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
java
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.StringTokenizer; import java.util.Tre...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct A { int x, id; } a[N]; bool cmp(A x, A y) { return x.x < y.x; } struct Edge { int to, next, id; } edge[N]; int n, s, head[N], num; void add_edge(int a, int b, int id) { edge[++num] = (Edge){b, head[a], id}, head[a] = num; } int f[N], ne[N]...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int a[200000], b[200000]; vector<int> pos[200000]; int p[200000], nxt[200000]; int parent[200000]; int find(int n) { if (parent[n] != n) parent[n] = find(parent[n]); return parent[n]; } int visited[200000]; vector<int> cycles[200000]; int main() { int i; int n, s; ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int N, S; vector<int> V; vector<int> nxt; vector<pair<int, int> > G[200005]; bool viz[200005]; map<int, int> normalize; vector<vector<int> > op; vector<int> dfs(int nod) { vector<int> tmp; while (!G[nod].empty()) { int v = G[nod].back().first; int tag = G[nod].b...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[200000]; int nxt[200000]; bool v[200000]; vector<int> cycle; void dfs(int now) { v[now] = true; while (nxt[now] < adj[now].size()) { cycle.push_back(adj[now][nxt[now]].second); dfs(adj[now][nxt[now]++].first); } } int main() { ios...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string a[2]; deque<int> d[2]; vector<pair<int, int> > v; int type[2]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> a[0] >> a[1]; a[0] += '$'; a[1] += '$'; for (int k = 0; k < 2; ++k) { int i = 0, n = ((int)a[k].size()) - 1; while (i ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, s, a[200010]; map<int, int> mp1; map<int, vector<int> > mp2; vector<vector<int> > ans; void dfs(int u) { while (!mp2[u].empty()) { int i = mp2[u].back(); mp2[u].pop_back(); dfs(a[i]); ans.back().push_back(i); } mp2.erase(u); } int main() { sca...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 100002; int n, s, a[N], c[N]; int tot, cnt; int b[N], use[N]; map<int, int> mp; vector<int> v[N]; void read(int &x) { char ch = getchar(); x = 0; for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k, tot, x, ans, a[1000000], b[1000000], f[1000000], ed[1000000], nt[1000000], nm[1000000], ss[1000000]; map<int, int> mp, rw; bool v[1000000]; int gf(int x) { if (f[x] == x) return x; f[x] = gf(f[x]); return f[x]; } int main() { scanf("%d %d", &n, &k); ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 520233; int n, s, a[N], b[N]; int fa[N]; int Find(int x) { return (fa[x] == x) ? x : (fa[x] = Find(fa[x])); } map<int, int> mp; bool Merge(int x, int y) { if (Find(x) != Find(y)) { fa[Find(x)] = Find(y); return true; } return false; } int p[N], c...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct A { int x, id; } a[N]; bool cmp(A x, A y) { return x.x < y.x; } int a0[N], s[N], f[N], pre[N], nxt[N]; int f_f(int x) { return x == f[x] ? x : f[x] = f_f(f[x]); } bool vv[N]; vector<int> t[N]; int main() { int n, S; scanf("%d%d", &n, &S); ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 202020, d = 0; int N, S, oval[MAXN], edge[MAXN], comp[MAXN], cnum = 0, vis[MAXN]; vector<int> comp_stack[MAXN]; pair<int, int> vals[MAXN]; vector<int> cursol; vector<vector<int> > solution; void recur(int n) { vis[comp[n]] = 1; while (comp_stack[comp[n]...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, s, a[200020], b[200020], p[200020]; bool cmp(int i, int j) { return a[i] < a[j]; } int rt[200020]; int findrt(int x) { if (rt[x] != x) rt[x] = findrt(rt[x]); return rt[x]; } int get(int x) { return lower_bound(b + 1, b + n + 1, x) - b; } map<int, int> S; int c[20...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int maxn = 100010, maxk = 100010, maxm = 100010, maxq = 100010, mod = 119 << 23 | 1; int n, m, q, e[maxn], cnt[maxm], ans[maxq]; struct Query { int id, l, r, k; void rd(int i) { id = i; scanf("%d%d%d", &l, &r, &k); --l; } bool operator<(const Query& q) const ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using namespace chrono; const int infinity = (int)1e9 + 42; const int64_t llInfinity = (int64_t)1e18 + 256; const int module = (int)1e9 + 7; const long double eps = 1e-8; mt19937_64 randGen(system_clock().now().time_since_epoch().count()); inline void raiseError(string erro...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, s, a[200020], b[200020], p[200020]; bool cmp(int i, int j) { return a[i] < a[j]; } int rt[200020]; int findrt(int x) { if (rt[x] != x) rt[x] = findrt(rt[x]); return rt[x]; } int get(int x) { return lower_bound(b + 1, b + n + 1, x) - b; } map<int, int> S[200020]; ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
java
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; public class E { int[] sorted(int[] a) { a = a.clone(); for (int i = 0; i < a.length; i++) { int j = rand(0, i); int tmp = a[i]; a[i] = a[j]; a[j] = tmp; } return a; } void submit() { int n = nextInt(); in...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, s, a[200020], b[200020], p[200020]; bool cmp(int i, int j) { return a[i] < a[j]; } int rt[200020]; int findrt(int x) { if (rt[x] != x) rt[x] = findrt(rt[x]); return rt[x]; } int get(int x) { return lower_bound(b + 1, b + n + 1, x) - b; } map<int, int> S; int c[20...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class BidirIt> BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) { advance(it, -n); return it; } template <class ForwardIt> ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::differenc...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct ln { int val; ln* next; }; vector<pair<int, int> >* nl; int* roi; bool* btdt; ln* fe(ln* ath, int cp) { ln* sv = NULL; for (int i = roi[cp]; i < nl[cp].size(); i = roi[cp]) { int np = nl[cp][i].first; int ind = nl[cp][i].second; if (btdt[ind]) { ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, f[N], to[N]; pair<int, int> a[N]; bool done[N]; int find(int x) { while (x != f[x]) { x = f[x] = f[f[x]]; } return x; } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i].first); a[i].s...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k, tot, x, a[1000000], b[1000000], f[1000000], ed[1000000], nt[1000000], nm[1000000]; map<int, int> mp, rw; bool v[1000000]; int gf(int x) { if (f[x] == x) return x; f[x] = gf(f[x]); return f[x]; } int main() { scanf("%d %d", &n, &k); for (int i = (1); ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, f[N], to[N]; pair<int, int> a[N]; bool done[N]; int find(int x) { while (x != f[x]) { x = f[x] = f[f[x]]; } return x; } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i].first); a[i].s...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxN = 200001; int T[maxN], Tsor[maxN], perm[maxN], fing[maxN]; bool vis[maxN]; map<int, int> M; vector<int> poss[maxN], cyc; int main() { int n, s; scanf("%d%d", &n, &s); for (int(i) = (1); (i) < (n + 1); (i)++) scanf("%d", T + i), Tsor[i] = T[i]; sort(Ts...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int a[200000], b[200000]; vector<int> pos[200000]; int p[200000], nxt[200000]; int parent[200000]; int find(int n) { if (parent[n] != n) parent[n] = find(parent[n]); return parent[n]; } int visited[200000]; vector<int> cycles[200000]; int main() { int i; int n, s; ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MN = 200010; int fa[MN]; void init() { for (int i = 0; i < MN; i++) fa[i] = i; } int find(int u) { if (fa[u] == u) return u; else return fa[u] = find(fa[u]); } void mrg(int u, int v) { u = find(u); v = find(v); if (u == v) return; fa[v] = u; ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct ln { int val; ln* next; }; vector<pair<int, int> >* nl; int* roi; bool* btdt; ln* fe(ln* ath, int cp) { for (int i = roi[cp]; i < nl[cp].size(); i = roi[cp]) { int np = nl[cp][i].first; int ind = nl[cp][i].second; if (btdt[ind]) { continue; ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct ln { int val; ln* next; }; vector<pair<int, int> >* nl; int* roi; bool* btdt; ln* fe(ln* ath, int cp) { for (int i = roi[cp]; i < nl[cp].size(); i = roi[cp]) { int np = nl[cp][i].first; int ind = nl[cp][i].second; if (btdt[ind]) { continue; ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class BidirIt> BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) { advance(it, -n); return it; } template <class ForwardIt> ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::differenc...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[200000]; int nxt[200000]; bool v[200000]; vector<int> cycle; void dfs(int now) { v[now] = true; while (nxt[now] < adj[now].size()) { cycle.push_back(adj[now][nxt[now]].second); nxt[now]++; dfs(adj[now][nxt[now] - 1].first); } } ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef vector<i...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; struct NODE { int val, pos; friend bool operator < (NODE a, NODE b) { return a.val < b.val; } }T[N]; int A[N], n, m, x, y, fa[N], s; bool vis[N]; vector < vector <int> > ans, cir; void print(void) { printf("%d\n", ans.size()); for(int i = ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template <class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } const int MAXN = 400013; int N, S, M, ans, n; int val[MAXN], arr[MAXN], sorted[MAXN]; vector<int> moves[MAXN]; vector<int> cyc...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200002; int n, s, a[N], c[N]; int tot, cnt; int b[N], use[N]; map<int, int> mp; vector<int> v[N]; void read(int &x) { char ch = getchar(); x = 0; for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class BidirIt> BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) { advance(it, -n); return it; } template <class ForwardIt> ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::differenc...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[200000]; int nxt[200000]; bool v[200000]; vector<int> cycle; void dfs(int now) { v[now] = true; while (nxt[now] < adj[now].size()) { cycle.push_back(adj[now][nxt[now]].second); dfs(adj[now][nxt[now]++].first); } } int main() { ios...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } set<int> s, pos[200200]; set<int>::iterator it; int a[200200], b[200200], vst[200200]; v...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
java
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.io.IOException; import java.util.Random; import java.util.ArrayList; import java.io.UncheckedIOException; import java.util.List; import java.io.Closeable; import java.io...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int N, S; vector<int> V; vector<int> nxt; vector<pair<int, int> > G[200005]; bool viz[200005]; map<int, int> normalize; vector<vector<int> > op; vector<int> dfs(int nod) { vector<int> tmp; if (!G[nod].empty()) { int v = G[nod].back().first; int tag = G[nod].back...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200600; int n, S; int a[N]; int b[N]; int xs[N]; int k; vector<int> g[N]; int m; vector<int> cycles[N]; int p[N]; bool used[N]; void dfs(int v) { while (!g[v].empty()) { int id = g[v].back(); g[v].pop_back(); dfs(a[id]); cycles[m].push_back(i...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using ll = int64_t; using ld = double; using ull = uint64_t; using namespace std; using namespace __gnu_pbds; const int MAXN = 200228; int nx[MAXN]; int p_[MAXN]; int p(int x) { return p_[x] == x ? ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int Maxn = 200005; int n, s, ct, tmp_n, ans_ct, a[Maxn], b[Maxn], fa[Maxn], pos[Maxn], ord[Maxn], bel[Maxn], Pos[Maxn]; vector<int> spec, Ve[Maxn]; bool vis[Maxn]; void dfs(int u) { if (vis[u]) return; bel[u] = ct, vis[u] = true, dfs(ord[u]); } void dfs2(int u...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, s; int niz[maxn], sol[maxn], saz[maxn]; vector<pair<int, int> > graph[maxn]; bool bio[maxn], bio2[maxn]; vector<int> sa; vector<vector<int> > al; vector<int> ac[maxn]; void dfs(int node) { bio2[node] = true; while (!graph[node].empty())...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, s; int niz[maxn], sol[maxn], saz[maxn]; vector<pair<int, int> > graph[maxn]; bool bio[maxn], bio2[maxn]; vector<int> sa; vector<vector<int> > al; vector<int> ac[maxn]; void dfs(int node) { bio2[node] = true; while (!graph[node].empty())...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 520233; int n, s, a[N], b[N]; int fa[N]; int Find(int x) { return (fa[x] == x) ? x : (fa[x] = Find(fa[x])); } map<int, int> mp; bool Merge(int x, int y) { if (Find(x) != Find(y)) { fa[Find(x)] = Find(y); return true; } return false; } int p[N], c...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long big = 1000000007; const long long mod = 998244353; long long n, m, k, T, q; vector<long long> A, A2; map<long long, long long> M; long long d = 0; long long pek[200001] = {0}; long long deg[200001] = {0}; long long par(long long i) { long long i2 = i; wh...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k, tot, x, a[1000000], b[1000000]; bool v[1000000]; vector<int> wr[1000000]; map<int, int> st; int main() { scanf("%d %d", &n, &k); for (int i = (1); i <= (n); i++) { scanf("%d", &a[i]); b[i] = a[i]; } sort(b + 1, b + n + 1); for (int i = (1); i <= ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:167772160000") using namespace std; void redirectIO() { ios::sync_with_stdio(false); cin.tie(0); } int n; int a[210000]; map<int, vector<int>> numberPositions; int s; int sa[210000]; int badPos; vector<vector<int>> vectors; bool vis[210000]; vector<int> curVe...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, s, a[N], f[N], nxt[N]; pair<int, int> b[N]; int getf(int v) { return f[v] == v ? v : f[v] = getf(f[v]); } bool vis[N]; void dfs1(int pos) { if (vis[pos]) return; vis[pos] = 1; f[pos] = getf(nxt[pos]); dfs1(nxt[pos]); } vector<int> cur; v...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, s; int a[200100]; int sorted[200100]; int been[200100]; map<int, list<int>> alive; list<list<int>> sol; void dfs(int val) { if (alive[val].empty()) return; int k = alive[val].front(); alive[val].pop_front(); been[k] = true; dfs(a[k]); sol.back().push_fron...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; int n, limit; int nxt[N], lab[N], flag[N]; pair<int, int> a[N]; vector<int> ans1, ans2; vector<vector<int> > ans3; vector<pair<int, int> > v; int root(int u) { if (lab[u] < 0) return u; return u = root(lab[u]); } void join(int u, int v) { int ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k, tot, x, ans, a[1000000], b[1000000], f[1000000], ed[1000000], nt[1000000], nm[1000000], ss[1000000]; map<int, int> mp, rw; bool v[1000000]; int gf(int x) { if (f[x] == x) return x; f[x] = gf(f[x]); return f[x]; } int main() { scanf("%d %d", &n, &k); ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, s, a[N], f[N], nxt[N]; pair<int, int> b[N]; int getf(int v) { return f[v] == v ? v : f[v] = getf(f[v]); } bool vis[N]; void dfs1(int pos) { if (vis[pos]) return; vis[pos] = 1; f[pos] = getf(nxt[pos]); dfs1(nxt[pos]); } vector<int> cur; v...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k, tot, x, ans, a[1000000], b[1000000], f[1000000], ed[1000000], nt[1000000], nm[1000000], ss[1000000]; map<int, int> mp, rw; bool v[1000000]; int gf(int x) { if (f[x] == x) return x; f[x] = gf(f[x]); return f[x]; } int main() { scanf("%d %d", &n, &k); ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; int n, limit; int nxt[N], lab[N], flag[N]; pair<int, int> a[N]; vector<int> ans1, ans2; vector<vector<int> > ans3; vector<pair<int, int> > v; int root(int u) { if (lab[u] < 0) return u; return lab[u] = root(lab[u]); } void join(int u, int v) { ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k, tot, x, a[1000000], b[1000000], f[1000000], ed[1000000], nt[1000000], nm[1000000]; map<int, int> mp, rw; bool v[1000000]; int gf(int x) { if (f[x] == x) return x; f[x] = gf(f[x]); return f[x]; } int main() { scanf("%d %d", &n, &k); for (int i = (1); ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') neg = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x * neg; } inline int qpow(int x, int e, int _MOD) { int ans = 1; ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
/* * Package: StandardCodeLibrary.Core * */ //引进常用的头文件并使用std名字空间; #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[200000]; int nxt[200000]; bool v[200000]; vector<int> cycle; void dfs(int now) { v[now] = true; while (nxt[now] < adj[now].size()) { cycle.push_back(adj[now][nxt[now]].second); nxt[now]++; dfs(adj[now][nxt[now] - 1].first); } } ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N], b[N], c[N], d[N], e[N]; using VI = vector<int>; VI v[N], rep[N]; int rn; void search(int u) { for (int U; !v[u].empty();) { U = v[u].back(); v[u].pop_back(); search(a[U]); rep[rn].push_back(U); } } int main() { int n, ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:167772160000") using namespace std; void redirectIO() { ios::sync_with_stdio(false); cin.tie(0); } int n; int a[210000]; map<int, vector<int>> numberPositions; int s; int sa[210000]; int badPos; vector<vector<int>> vectors; bool vis[210000]; vector<int> curVe...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, s; int niz[maxn], sol[maxn], saz[maxn]; vector<pair<int, int> > graph[maxn]; bool bio[maxn], bio2[maxn]; vector<int> sa; vector<vector<int> > al; vector<int> ac[maxn]; void dfs(int node) { bio2[node] = true; while (!graph[node].empty())...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct th { int num, pl; bool operator<(const th &a) const { if (num != a.num) return num < a.num; return pl < a.pl; } } p[200005]; int nx[200005]; int n, s; bool flag[200005]; int fa[200005]; int gfa(int a) { if (fa[a] == a) return a; return fa[a] = gfa(f...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 20; int arr[MAXN], srt[MAXN]; bool bio[MAXN]; vector<pair<int, int>> edges[MAXN]; vector<vector<int>> cyc; void euler(int i) { bio[i] = true; while (!edges[i].empty()) { auto x = edges[i].back(); edges[i].pop_back(); euler(x.first); ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class BidirIt> BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) { advance(it, -n); return it; } template <class ForwardIt> ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::differenc...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int dsu[N]; int rang[N]; int pred(int a) { if (a == dsu[a]) return a; return dsu[a] = pred(dsu[a]); } void unite(int a, int b) { a = pred(a); b = pred(b); if (a != b) { if (rang[a] < rang[b]) { swap(a, b); } dsu[b] = a; ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,b) rng(i,0,b) #define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--) #define per(i,b) gnr(i,0,b) #define pb push_back #define eb emplace_back #define a first #define b second ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k, tot, x, ans, a[1000000], b[1000000], f[1000000], ed[1000000], nt[1000000], nm[1000000], ss[1000000]; map<int, int> mp, rw; bool v[1000000]; int gf(int x) { if (f[x] == x) return x; f[x] = gf(f[x]); return f[x]; } int main() { scanf("%d %d", &n, &k); ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[200000]; int nxt[200000]; bool v[200000]; vector<int> cycle; void dfs(int now) { v[now] = true; while (nxt[now] < adj[now].size()) { cycle.push_back(adj[now][nxt[now]].second); nxt[now]++; dfs(adj[now][nxt[now] - 1].first); } } ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct ln { int val; ln* next; }; vector<pair<int, int> >* nl; int* roi; bool* btdt; ln* fe(ln* ath, int cp) { ln* sv = NULL; for (int i = roi[cp]; i < nl[cp].size(); i = roi[cp]) { int np = nl[cp][i].first; int ind = nl[cp][i].second; if (btdt[ind]) { ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
java
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.StringTokenizer; import java.util.Tre...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int mxN = 2e5; int n, s, a[mxN]; map<int, int> mp1; map<int, vector<int>> mp2; vector<vector<int>> ans; void dfs(int u) { while (!mp2[u].empty()) { int i = mp2[u].back(); mp2[u].pop_back(); ans.back().push_back(i); dfs(a[i]); } mp2.erase(u); } in...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, s; int a[200001]; pair<int, int> b[200001]; bool gd[200001]; int par[200001]; int nxt[200001]; bool vis[200001]; int use; int q; int cur[200001]; int find(int x) { if (par[x] != x) par[x] = find(par[x]); return par[x]; } void join(int x, int y, int z) { x = fin...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int max_n = 200222, inf = 1000111222; int n, s, cnt, to[max_n]; int a[max_n], b[max_n], pos[max_n]; vector<int> all[max_n]; void compress() { pair<int, int> p[max_n]; for (int i = 0; i < n; ++i) { p[i] = {a[i], i}; } sort(p, p + n); int num = 0; for (i...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> const int MAX_N = 200000; int v[1 + MAX_N], poz[1 + MAX_N], sorted[1 + MAX_N]; bool cmp(int a, int b) { return v[a] < v[b]; } std::vector<int> src[1 + MAX_N], target[1 + MAX_N]; void normalize(int n) { std::sort(poz + 1, poz + 1 + n, cmp); int last = v[poz[1]], j = 1; for (int i = 1; i <=...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, t...); } ...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename T> vector<T>& operator--(vector<T>& v) { for (auto& i : v) --i; return v; } template <typename T> vector<T>& operator++(vector<T>& v) { for (auto& i : v) ++i; return v; } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template <class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } const int MAXN = 400013; int N, S, M, ans, n; int val[MAXN], arr[MAXN]; vector<int> moves[MAXN]; vector<int> cyc[MAXN]; bitset...
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n" ], "output": [ "1\n5\n1 4 2 3 5 \n", "-1\n", "0\n" ] }
{ "input": [ "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n4727783...
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, s, a[200020], b[200020], p[200020]; bool cmp(int i, int j) { return a[i] < a[j]; } int rt[200020]; int findrt(int x) { if (rt[x] != x) rt[x] = findrt(rt[x]); return rt[x]; } int get(int x) { return lower_bound(b + 1, b + n + 1, x) - b; } map<int, int> S[200020]; ...