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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int fail() {
printf("-1\n");
return 0;
}
const int MN = 2e5 + 100;
const int MS = MN;
int N, S, a[MN], v[MN], g[MN], V, f;
using i2 = array<int, 2>;
i2 b[MN];
using vi2 = vector<i2>;
vi2 w[MN];
bool u[MN];
using vi = vector<int>;
vi c[MN];
int C;
void dfs(int n, int p =... |
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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
struct node {
int id, x;
} a[202020], b[202020];
int n, S, doe, cnt;
int fa[202020], size[202020], r[202020], id[202020];
vector<int> col[202020];
bool br[202020];
bool cmp_id(node u, node w) { return u.id < w.id; }
bool cmp_x(node u, node w) { return u.x < w.x; }
int 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using pii = pair<int, int>;
int n, s;
int a[200010], b[200010];
int p[200010];
bool used[200010];
int fth[200010];
vector<vector<int>> cycles;
map<int, vector<int>> v, pos;
int root(int x) { return fth[x] == -1 ? x : fth[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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int p[200005], rk[200005];
vector<int> g[200005];
int m;
int a[200005];
int b[200005];
int uq[200005];
bool used[200005];
vector<int> cycles[200005];
void dfs(int u) {
while (!g[u].empty()) {
int i = g[u].back();
g[u].pop_back();
dfs(a[i]);
cycles[m].push_... |
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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using int64 = long long int;
struct Edge {
int from;
int to;
int to_index;
};
class Graph {
public:
explicit Graph(const int n) : edges_(n) {}
void AddEdge(Edge e) { edges_[e.from].push_back(e); }
vector<vector<int>> FindCycles() {
current_edge_.assign(edge... |
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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int b[N], no[N], n0, n, sum, cnt = 0, to[N], vis[N], ran[N];
vector<int> vec[N];
struct nd {
int id, vl;
} a[N];
struct edge {
int to, id;
};
vector<edge> e[N];
bool cmp(nd x, nd y) { return x.vl < y.vl; }
void init() {
int i;
for (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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, F = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') F = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * F;
}
int n, cnt, s, F, tmp;
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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &x, T y) {
return x < y ? x = y, true : false;
}
template <typename T>
bool chkmin(T &x, T y) {
return x > y ? x = y, true : false;
}
int readint() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (... |
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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 200005;
map<int, int> MP;
struct node {
int a, b;
inline node() {}
inline node(int a, int b) : a(a), b(b) {}
bool operator<(node x) const { return a < x.a; }
} nod[N];
int a[N], nxt[N], fa[N], rt[N], sz[N], b[N];
int find(int v) { return fa[v] == 0 ? 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using int64 = long long int;
struct Edge {
int from;
int to;
int to_index;
};
class Graph {
public:
explicit Graph(const int n) : edges_(n) {}
void AddEdge(Edge e) { edges_[e.from].push_back(e); }
vector<vector<int>> FindCycles() {
vector<vector<int>> resul... |
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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
vector<int> circuit;
vector<int> e[MAXN];
void calc(int v) {
stack<int> s;
while (true) {
if (((int)e[v].size()) == 0) {
circuit.push_back(v);
if (!((int)s.size())) {
break;
}
v = s.top();
s.pop();
... |
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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, S;
int a[N], p[N], q[N];
vector<vector<int>> cir;
int uf[N];
int find(int x) { return (uf[x] == x) ? (x) : (uf[x] = find(uf[x])); }
void adjust() {
for (int i = 1; i <= n; i++) {
uf[i] = i;
}
pair<int, int>* b = new pair<int, 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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, s, t, ans, a[N];
int p[N], fa[N];
pair<int, int> b[N];
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
bool vis[N];
vector<int> c[N];
void dfs(int x) {
vis[x] = 1;
c[t].push_back(x);
if (!vis[p[x]]) dfs(p[x]);
}
int main() {... |
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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
vector<int> new_val;
inline int Val(int first) {
return lower_bound(new_val.begin(), new_val.end(), first) - new_val.begin();
}
void Move(vector<int> &ind, vector<int> &a) {
int last = a[ind.back()];
for (int i : ind) {
swap(a[i], last);
}
}
int n, s;
void Dfs(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... | 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();
dfs(a[i]);
ans.back().push_back(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... | 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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
int n, m, len, a[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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
int a[N], p[N], head[N], now = 0;
pair<int, int> b[N];
vector<int> cycle[N];
int findd(int x) {
if (head[x] < 0) {
return x;
}
return head[x] = findd(head[x]);
}
void unionn(int x, int y) {
x = findd(x), y = findd(y);
head[x] += head[y];... |
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... | 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>
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;
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;
using namespace rel_ops;
using ll = int64_t;
using Pii = pair<int, int>;
using ull = uint64_t;
using Vi = vector<int>;
void run();
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
run();
return 0;
}
struct Vert {
Vi E, src;
};
... |
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;
int N, S, cnt;
int A[200005], A2[200005];
bool Use[200005];
int P[200005];
map<int, int> X;
int cyc, R[200005], TT[200005];
vector<int> V[200005], Cycle[200005];
void Read() {
scanf("%d%d", &N, &S);
for (int i = 1; i <= N; i++) {
scanf("%d", &A[i]);
A2[i] = A[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 | #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef complex... |
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 + 5;
vector<int> circuit;
vector<int> e[MAXN];
void calc(int v) {
stack<int> s;
while (true) {
if (((int)e[v].size()) == 0) {
circuit.push_back(v);
if (!((int)s.size())) {
break;
}
v = s.top();
s.pop();
... |
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<int> pat[500000];
vector<int> rev[500000];
vector<bool> flag[500000];
int pt[500000];
void adde(int a, int b) {
pat[a].push_back(b);
flag[a].push_back(false);
}
vector<int> euler;
void calceuler(int node) {
for (;;) {
if (pt[node] == pat[node].size()) break... |
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, cnt;
int A[200005], A2[200005];
bool Use[200005];
int P[200005];
map<int, int> X;
int cyc, R[200005], TT[200005];
vector<int> V[200005], Cycle[200005];
void Read() {
scanf("%d%d", &N, &S);
for (int i = 1; i <= N; i++) {
scanf("%d", &A[i]);
A2[i] = A[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;
} edge[N];
int head[N], num;
void add_edge(int a, int b) { edge[++num] = (Edge){b, head[a]}, head[a] = num; }
int f[N], cc[N], c0, c1;
bool vis[N], 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]);
if (!alive[val].empt... |
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 + 20;
int a[maxn], q[maxn], num[maxn], par[maxn];
bool visited[maxn];
vector<int> ind[maxn], cycle[maxn];
int f(int v) { return (par[v] == -1) ? v : par[v] = f(par[v]); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
me... |
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;
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 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;
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 | 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 MAXN = 2e5 + 5;
vector<int> circuit;
vector<int> e[MAXN];
void calc(int v) {
stack<int> s;
while (true) {
if (((int)e[v].size()) == 0) {
circuit.push_back(v);
if (!((int)s.size())) {
break;
}
v = s.top();
s.pop();
... |
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 cat = long long;
void DFS(int R, vector<vector<int> >& G, vector<bool>& vis, vector<int>& cyc) {
cyc.push_back(R);
vis[R] = true;
while (!G[R].empty()) {
int v = G[R].back();
G[R].pop_back();
DFS(v, G, vis, cyc);
}
}
int main() {
cin.sync_with_st... |
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 + 5;
int n, s, a[N], aa[N], g[N], p[N], i, j;
int gfa(int x) { return g[x] == x ? x : g[x] = gfa(g[x]); }
bool bb[N], vi[N];
set<int> S;
unordered_map<int, int> be, en;
unordered_map<int, vector<int>> mp;
int main() {
ios::sync_with_stdio(0);
cin.tie(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 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 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;
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>
#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 = 5228;
struct St : vector<int> {
int pop() {
int x = 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>
int n, s, a[200010], b[200010], nums[200010], cnt, fa[200010];
int find(int i) { return fa[i] == i ? i : fa[i] = find(fa[i]); }
bool tag[200010];
struct edge {
int to;
edge* next;
} E[200010], *fir[200010];
std::vector<int> C[200010];
void dfs(int i, int t) {
while (fir[i]) {
edge* e ... |
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 inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename 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;
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 maxn = 2e5 + 20;
int a[maxn], q[maxn], num[maxn], par[maxn];
bool visited[maxn];
vector<int> ind[maxn], cycle[maxn];
int f(int v) { return (par[v] == -1) ? v : par[v] = f(par[v]); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
me... |
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 uint = unsigned int;
using ll = long long;
using pii = pair<int, int>;
int n, s;
int a[200010], b[200010];
int p[200010];
bool used[200010];
int fth[200010];
vector<vector<int>> cycles;
map<int, vector<int>> v, pos;
int root(int x) { return fth[x] == -1 ? x : fth[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 | 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 = 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.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 | 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 a[200010], b[200010], nxt[200010], cnt, n, s;
void solve(vector<int> &v, int i, int &j) {
while (a[j] == a[i]) j++;
if (j >= n) return;
if (b[j] == a[i]) {
swap(a[i], a[j]);
cnt++;
v.push_back(j++);
solve(v, i, nxt[lower_bound(b, b + n, a[i]) - 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 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>
using namespace std;
int n, m, a[200010], b[200010], x[200010], y[200010], f[200010], r[200010], p;
map<int, int> h;
inline int fa(int i) { return f[i] == i ? i : f[i] = fa(f[i]); }
inline void unit(int i, int j) {
i = fa(i);
j = fa(j);
if (i != j) f[i] = j;
}
int main() {
int i, j, 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 = 2e5 + 20;
int a[maxn], q[maxn], num[maxn], par[maxn];
bool visited[maxn];
vector<int> ind[maxn], cycle[maxn];
int f(int v) { return (par[v] == -1) ? v : par[v] = f(par[v]); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
me... |
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 | 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;
vector<int> pat[500000];
vector<int> rev[500000];
vector<bool> flag[500000];
int pt[500000];
void adde(int a, int b) {
pat[a].push_back(b);
flag[a].push_back(false);
}
vector<int> euler;
void calceuler(int node) {
for (;;) {
if (pt[node] == pat[node].size()) break... |
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 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 = 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 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();
dfs(a[i]);
ans.back().push_back(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 get() {
char ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-') {
int s = 0;
while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
return -s;
}
int s = ch - '0';
while (ch = getchar(), ch >= '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 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;
const int N = 200005;
map<int, int> MP;
struct node {
int a, b;
inline node() {}
inline node(int a, int b) : a(a), b(b) {}
bool operator<(node x) const { return a < x.a; }
} nod[N];
int a[N], nxt[N], fa[N], rt[N], sz[N], b[N];
int find(int v) { return fa[v] == 0 ? 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, a[200079], p[200079];
vector<pair<int, int> > b(200079);
int rodic[200079], r[200079];
int najdisef(int v) {
if (rodic[v] == v) return v;
rodic[v] = najdisef(rodic[v]);
return rodic[v];
}
void spojset(int i, int j) {
i = najdisef(i);
j = najdisef(j);
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 = 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 | 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 gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
int n, lim;
int a[MAXN];
int b[MAXN];
bool isfixed[MAXN];
pair<int, int> o[MAXN];
int no;
int dst[MAXN];
int cyc[MAXN], ncyc;
int par[MAXN], sz[MAXN];
int find(int a) {
if (par[a] == 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;
vector<pair<int, int> > adj[200000];
int nxt[200000];
bool v[200000];
vector<int> cycle;
void dfs(int now, int src) {
if (nxt[now] == adj[now].size()) {
assert(now == src);
return;
}
v[now] = true;
cycle.push_back(adj[now][nxt[now]].second);
nxt[now]++;
... |
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 + 20;
int a[maxn], q[maxn], num[maxn], par[maxn];
bool visited[maxn];
vector<int> ind[maxn], cycle[maxn];
int f(int v) { return (par[v] == -1) ? v : par[v] = f(par[v]); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
me... |
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 rel_ops;
using ll = int64_t;
using Pii = pair<int, int>;
using ull = uint64_t;
using Vi = vector<int>;
void run();
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
run();
return 0;
}
struct Vert {
Vi E, src;
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 MAXN = 300000;
map<int, int> mapa;
map<pair<int, int>, vector<int>> pos;
vector<int> g[MAXN];
int ptr[MAXN];
int used[MAXN];
void euler(int v, vector<int> &res) {
used[v] = true;
for (; ptr[v] < (int)(g[v]).size();) {
++ptr[v];
int u = g[v][ptr[v] - 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 | 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... |
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 = 300000;
map<int, int> mapa;
vector<int> pos[MAXN];
vector<int> g[MAXN];
int ptr[MAXN];
int used[MAXN];
void euler(int v, vector<int> &res) {
used[v] = true;
for (; ptr[v] < (int)(g[v]).size();) {
++ptr[v];
euler(g[v][ptr[v] - 1], res);
}
if ... |
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 fail() {
printf("-1\n");
return 0;
}
const int MN = 2e5 + 100;
const int MS = MN;
int N, S, a[MN], v[MN], g[MN], V, f;
using i2 = array<int, 2>;
i2 b[MN];
using vi2 = vector<i2>;
vi2 w[MN];
bool u[MN];
using vi = vector<int>;
vi c[MN];
int C;
void dfs(int n, int p =... |
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>
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;
const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const long long int INF = 1e18 + 9LL;
int n, s;
int in[N];
int last[N];
int sorted[N];
set<int> place[N];
set<int> value[N];
int cnt;
map<int, int> M;
int dir[N];
bool vis[N];
vector<int> cur;
void solve(int c) {
if (place[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;
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;
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;
const int INF = 0x3f2f1f0f;
const long long LINF = 1ll * INF * INF;
const int MAX_N = 2e5 + 100;
int N, S, Nr[MAX_N], Sort[MAX_N];
vector<int> Nrs[MAX_N], Sorts[MAX_N];
vector<vector<int>> Ans;
int Go[MAX_N];
int main() {
srand(2016101);
cin >> N >> S;
vector<int> Co;... |
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 = 1e6 + 7;
const int MX = 1e9 + 7;
const long long int INF = 1e18 + 9LL;
int n, s;
int in[N];
int last[N];
int sorted[N];
set<int> place[N];
set<int> value[N];
int cnt;
map<int, int> M;
int dir[N];
bool vis[N];
vector<int> cur;
void solve(int c) {
if (place[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 = 2e5 + 25;
int a[N], b[N], c[N], cycsz;
vector<int> g[N], cyc[N];
void dfs(int v) {
while (!g[v].empty()) {
int u = g[v].back();
g[v].pop_back();
dfs(a[u]);
cyc[cycsz].push_back(u);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(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;
struct Data {
int v, i;
bool operator<(const Data &r) const { return v < r.v || v == r.v && i < r.i; }
};
int n, s, a[200000];
Data so[200000];
int main() {
while (scanf("%d %d", &n, &s) != EOF) {
for (int i = int(0); i < int(n); i++) {
scanf("%d", &a[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;
using cat = long long;
void DFS(int R, vector<vector<int> >& G, vector<bool>& vis, vector<int>& cyc) {
cyc.push_back(R);
vis[R] = true;
while (!G[R].empty()) {
int v = G[R].back();
G[R].pop_back();
DFS(v, G, vis, cyc);
}
}
int main() {
cin.sync_with_st... |
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;
const int N = 2e5 + 5;
int n, S;
int a[N], p[N], q[N];
vector<vector<int>> cir;
int uf[N];
int find(int x) { return (uf[x] == x) ? (x) : (uf[x] = find(uf[x])); }
void adjust() {
for (int i = 1; i <= n; i++) {
uf[i] = i;
}
pair<int, int>* b = new pair<int, 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>
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;
const int MAXN = 300000;
map<int, int> mapa;
vector<int> pos[MAXN];
vector<int> g[MAXN];
int ptr[MAXN];
int used[MAXN];
void euler(int v, vector<int> &res) {
used[v] = true;
for (; ptr[v] < (int)(g[v]).size();) {
++ptr[v];
euler(g[v][ptr[v] - 1], res);
}
if ... |
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[252525];
int sorted[252525];
bool vis[252525];
bool numvis[252525];
bool cycvis[252525];
vector<vector<int> > cyc;
int color[252525];
vector<vector<int> > conn;
int num[252525];
vector<vector<int> > ans;
vector<int> curr;
void dfs(int cycno, int starting) {
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.