Search is not available for this dataset
name stringlengths 2 88 | description stringlengths 31 8.62k | public_tests dict | private_tests dict | solution_type stringclasses 2
values | programming_language stringclasses 5
values | solution stringlengths 1 983k |
|---|---|---|---|---|---|---|
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 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;
const int N = 520233;
int n, s, a[N], b[N];
int fa[N];
int Find(int x) { return (fa[x] == x) ? x : (fa[x] = Find(fa[x])); }
map<int, int> mp;
bool Merge(int x, int y) {
if (Find(x) != Find(y)) {
fa[Find(x)] = Find(y);
return true;
}
return false;
}
int p[N], c... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int v[300300];
int a[300300];
int b[300300];
set<int> pos[300300];
int nxt[300300];
int pai[300300];
int last[300300];
int find(int x) { return pai[x] = (x == pai[x]) ? x : find(pai[x]); }
void merge(int A, int B) {
A = find(A);
B = find(B);
pai[A] = B;
}
int mrk[3003... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, k, tot, x, ans, a[1000000], b[1000000], f[1000000], ed[1000000],
nt[1000000], nm[1000000], ss[1000000];
map<int, int> mp, rw;
bool v[1000000];
int gf(int x) {
if (f[x] == x) return x;
f[x] = gf(f[x]);
return f[x];
}
int main() {
scanf("%d %d", &n, &k);
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long maxn = 4e5 + 10;
long long a[maxn], b[maxn], f[maxn];
vector<long long> v[maxn];
map<long long, long long> mp;
vector<vector<long long> > ans;
vector<long long> vec;
bool mark[maxn];
long long par[maxn];
long long Find(long long x) {
return (par[x] < 0 ? x... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include<bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
using namespace std;
typedef vector<int> Vi;
inline void read(int &x) {
x=0; char... |
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 = 100010;
struct A {
int x, id;
} a[N];
bool cmp(A x, A y) { return x.x < y.x; }
int a0[N], s[N], f[N], pre[N], nxt[N];
int f_f(int x) { return x == f[x] ? x : f[x] = f_f(f[x]); }
bool vv[N];
vector<int> t[N];
int main() {
int n, S;
scanf("%d%d", &n, &S);
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 200002;
int n, s, a[N], c[N];
int tot, cnt;
int b[N], use[N];
map<int, int> mp;
vector<int> v[N];
void read(int &x) {
char ch = getchar();
x = 0;
for (; ch < '0' || ch > '9'; ch = getchar())
;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
if (a < b) a = b;
}
const int MAXN = 400013;
int N, S, M, ans, n;
int val[MAXN], arr[MAXN], sorted[MAXN];
vector<int> moves[MAXN];
vector<int> cyc... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int 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;
const int max_n = 222, mod = 1000000007;
int n, p[max_n], to[max_n][2];
string s;
void get_prefix_function(const string &s, int p[]) {
p[0] = 0;
for (int i = 1; i < s.length(); ++i) {
p[i] = p[i - 1];
while (p[i] > 0 && s[i] != s[p[i]]) {
p[i] = p[p[i] - 1... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class BidirIt>
BidirIt prev(BidirIt it,
typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
typename iterator_traits<ForwardIt>::differenc... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long Inf = 1e18;
const int N = 2e5 + 10;
const int mod = 0;
int gi() {
int x = 0, o = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') o = -1, ch = getchar();
while (ch >= '0' && ch ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<doub... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int Maxn = 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;
int n, k, tot, x, a[1000000], b[1000000], st[1000000], ed[1000000], nt[1000000];
vector<int> wr[1000000];
bool v[1000000];
int main() {
scanf("%d %d", &n, &k);
for (int i = (1); i <= (n); i++) {
scanf("%d", &a[i]);
b[i] = a[i];
}
sort(b + 1, b + n + 1);
fo... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, s, a[200020], b[200020], p[200020];
bool cmp(int i, int j) { return a[i] < a[j]; }
int rt[200020];
int findrt(int x) {
if (rt[x] != x) rt[x] = findrt(rt[x]);
return rt[x];
}
int get(int x) { return lower_bound(b + 1, b + n + 1, x) - b; }
map<int, int> S;
int c[20... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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;
int n, k, tot, x, ans, a[1000000], b[1000000], f[1000000], ed[1000000],
nt[1000000], nm[1000000], ss[1000000];
map<int, int> mp, rw;
bool v[1000000];
int gf(int x) {
if (f[x] == x) return x;
f[x] = gf(f[x]);
return f[x];
}
int main() {
scanf("%d %d", &n, &k);
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int 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, S;
int A[200020], B[200020];
vector<int> vx;
set<pair<int, int> > E[200020];
void dfs(int x, vector<int> &R) {
while (1) {
auto it = E[x].begin();
if (it == E[x].end()) return;
pair<int, int> save = *it;
E[x].erase(it);
dfs(save.second, R);
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long mod7 = 1000000007LL;
inline long long getint() {
long long _x = 0, _tmp = 1;
char _tc = getchar();
while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
if (_tc == '-') _tc = getchar(), _tmp = -1;
while (_tc >= ... |
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]) {
int j0 = j++;
swap(a[i], a[j0]);
while (b[j0] == b[j]) {
if (b[j] != a[j]) {
v.pus... |
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;
int a[200010];
int b[200010];
vector<pair<int, int> > graf[200010];
vector<int> tura;
vector<int> sz;
vector<vector<int> > sol;
vector<vector<int> > rj;
vector<int> r;
int bio[200010];
void dfs(int x) {
bio[x] = 1;
while (!graf[x].empty()) {
int sus = graf... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int Maxn = 200005;
int n, s, ct, tmp_n, ans_ct, a[Maxn], b[Maxn], fa[Maxn], pos[Maxn], ord[Maxn],
bel[Maxn], Pos[Maxn];
vector<int> spec, Ve[Maxn];
bool vis[Maxn];
void dfs(int u) {
if (vis[u]) return;
bel[u] = ct, vis[u] = true, dfs(ord[u]);
}
void dfs2(int u... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 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 = 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;
template <class T, class U>
void ckmin(T &a, U b) {
if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
if (a < b) a = b;
}
const int MAXN = 400013;
int N, S, M, ans, n;
int val[MAXN], arr[MAXN], sorted[MAXN];
vector<int> moves[MAXN];
vector<int> cyc... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | 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;
const long long maxn = 2e5 + 500;
const long long mod = 1e9 + 7;
const long long inf = 2e9 + 500;
long long a[maxn];
long long sorta[maxn];
long long f[maxn];
void comp(long long n) {
vector<long long> vec;
for (long long i = 1; i <= n; i++) {
vec.push_back(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 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;
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 = 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... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 202020, d = 0;
int N, S, oval[MAXN], edge[MAXN], comp[MAXN], cnum = 0, vis[MAXN];
vector<int> comp_stack[MAXN];
pair<int, int> vals[MAXN];
vector<int> cursol;
vector<vector<int> > solution;
void recur(int n) {
vis[comp[n]] = 1;
while (comp_stack[comp[n]... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int 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 inf = 1e9;
const long long Inf = 1e18;
const int N = 2e5 + 10;
const int mod = 0;
int gi() {
int x = 0, o = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') o = -1, ch = getchar();
while (ch >= '0' && ch ... |
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;
const int Maxn = 200005;
int n, s, ct, tmp_n, ans_ct, a[Maxn], b[Maxn], fa[Maxn], pos[Maxn], ord[Maxn],
bel[Maxn], Pos[Maxn];
vector<int> spec, Ve[Maxn];
bool vis[Maxn];
void dfs(int u) {
if (vis[u]) return;
bel[u] = ct, vis[u] = true, dfs(ord[u]);
}
void dfs2(int u... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 520233;
int n, s, a[N], b[N];
int fa[N];
int Find(int x) { return (fa[x] == x) ? x : (fa[x] = Find(fa[x])); }
map<int, int> mp;
bool Merge(int x, int y) {
if (Find(x) != Find(y)) {
fa[Find(x)] = Find(y);
return true;
}
return false;
}
int p[N], c... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
using namespace std;
typedef long long ll;
type... |
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;
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 | 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 ... |
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 | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, s, a[N], f[N], nxt[N];
pair<int, int> b[N];
int getf(int v) { return f[v] == v ? v : f[v] = getf(f[v]); }
bool vis[N];
void dfs1(int pos) {
if (vis[pos]) return;
vis[pos] = 1;
f[pos] = getf(nxt[pos]);
dfs1(nxt[pos]);
}
vector<int> cur;
v... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MN = 200010;
int fa[MN];
void init() {
for (int i = 0; i < MN; i++) fa[i] = i;
}
int find(int u) {
if (fa[u] == u)
return u;
else
return fa[u] = find(fa[u]);
}
void mrg(int u, int v) {
u = find(u);
v = find(v);
fa[v] = u;
}
int N, S;
int A[MN],... |
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 | 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 cnt, n, m, k, i, j, a[200200], b[200200], c[200200], p[200200];
vector<vector<int>> r;
vector<int> g[200200];
bool u[200200];
void dfs(int i, int ed) {
u[i] = true;
while (p[i] < g[i].size()) {
int cur = g[i][p[i]];
p[i]++;
dfs(b[cur], cur);
}
if (ed... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int Maxn = 200005;
int n, s, ct, tmp_n, ans_ct, a[Maxn], b[Maxn], fa[Maxn], pos[Maxn], ord[Maxn],
bel[Maxn], Pos[Maxn];
vector<int> spec, Ve[Maxn];
bool vis[Maxn];
void dfs(int u) {
if (vis[u]) return;
bel[u] = ct, vis[u] = true, dfs(ord[u]);
}
void dfs2(int u... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> cyc[N], vec[N];
int a[N], b[N], c[N], p[N], flag[N];
void find(int u, int m) {
for (; vec[u].size();) {
int v = vec[u].back();
vec[u].pop_back();
find(a[v], m);
cyc[m].push_back(v);
}
}
int main() {
int n, s;
cin >... |
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, sz, cnt, tot, sum, A[200000 + 5], T[200000 + 5], Cnt[200000 + 5],
Id[200000 + 5], Head[200000 + 5];
vector<int> Road[200000 + 5];
bool Flag[200000 + 5];
struct Edge {
int next, node, w;
} h[200000 + 5];
void addedge(int u, int v, int w) {
h[++tot].next = H... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class BidirIt>
BidirIt prev(BidirIt it,
typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
typename iterator_traits<ForwardIt>::differenc... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
os << '[';
for (unsi... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename TH>
void _dbg(const char* sdbg, TH h) {
cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, t...);
}
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class BidirIt>
BidirIt prev(BidirIt it,
typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
typename iterator_traits<ForwardIt>::differenc... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 200002;
int n, s, a[N], c[N];
int tot, cnt;
int b[N], use[N];
map<int, int> mp;
vector<int> v[N];
void read(int &x) {
char ch = getchar();
x = 0;
for (; ch < '0' || ch > '9'; ch = getchar())
;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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;
}
int y = findd(head[x]);
head[x] = y;
return y;
}
void unionn(int x, int y) {
x = findd(x), y = findd(y);
h... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, k, tot, x, a[1000000], b[1000000];
bool v[1000000];
vector<int> wr[1000000];
map<int, int> st;
int main() {
scanf("%d %d", &n, &k);
for (int i = (1); i <= (n); i++) {
scanf("%d", &a[i]);
b[i] = a[i];
}
sort(b + 1, b + n + 1);
for (int i = (1); i <= ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int N, S;
int a[500010], b[500010];
bool done[500010], tt[500010];
map<int, int> L, R;
vector<vector<int> > ans;
set<int> st;
int find(int j) {
int v = a[j];
return *st.lower_bound(L[v]);
}
int main() {
scanf("%d%d", &N, &S);
for (int i = 1; i <= N; i++) scanf("%d",... |
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 + 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;
}
int y = findd(head[x]);
head[x] = y;
return y;
}
void unionn(int x, int y) {
x = findd(x), y = findd(y);
h... |
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 = 200005;
int n, s, ct, tmp_n, ans_ct, a[Maxn], b[Maxn], fa[Maxn], pos[Maxn], ord[Maxn],
bel[Maxn], Pos[Maxn];
vector<int> spec, Ve[Maxn];
bool vis[Maxn];
void dfs(int u) {
if (vis[u]) return;
bel[u] = ct, vis[u] = true, dfs(ord[u]);
}
void dfs2(int u... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 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... | 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;
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 | 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;
template <class BidirIt>
BidirIt prev(BidirIt it,
typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
typename iterator_traits<ForwardIt>::differenc... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 100002;
int n, s, a[N], c[N];
int tot, cnt;
int b[N], use[N];
map<int, int> mp;
vector<int> v[N];
void read(int &x) {}
void prt(int o) {
for (int i = (0); i < (v[o].size()); i++) printf("%d ", v[o][i]);
}
int main() {
read(n);
read(s);
for (int i = (1)... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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 + 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;
const int N = 200010;
struct A {
int x, id;
} a[N];
bool cmp(A x, A y) { return x.x < y.x; }
struct Edge {
int to, next;
} edge[N];
int n, s, head[N], num;
void add_edge(int a, int b) { edge[++num] = (Edge){b, head[a]}, head[a] = num; }
int f[N], ne[N], cc[N], c0, c1;
b... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int 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;
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 | 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;
const int N = 4e5 + 10;
int Begin[N], Next[N], to[N], e;
void add(int u, int v) { to[++e] = v, Next[e] = Begin[u], Begin[u] = e; }
int n, m, k, c;
int A[N], rk[N], st[N], vis[N];
void DFS(int o) {
vis[o] = true;
for (int &i = Begin[o]; i;) {
int u = to[i];
i = 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;
template <typename TH>
void _dbg(const char* sdbg, TH h) {
cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, t...);
}
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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;
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;
}
int y = findd(head[x]);
head[x] = y;
return y;
}
void unionn(int x, int y) {
head[x] += head[y];
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... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
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;
}
int y = findd(head[x]);
head[x] = y;
return y;
}
void unionn(int x, int y) {
x = findd(x), y = findd(y);
h... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, s, a[200020], b[200020], p[200020];
bool cmp(int i, int j) { return a[i] < a[j]; }
int rt[200020];
int findrt(int x) {
if (rt[x] != x) rt[x] = findrt(rt[x]);
return rt[x];
}
int get(int x) { return lower_bound(b + 1, b + n + 1, x) - b; }
map<int, int> S[200020];
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | 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;
template <class T, class U>
void ckmin(T &a, U b) {
if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
if (a < b) a = b;
}
const int MAXN = 400013;
int N, S, M, ans, n;
int val[MAXN], arr[MAXN];
vector<int> moves[MAXN];
vector<int> cyc[MAXN];
bitset... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;
const int MAXN = 200228;
int nx[MAXN];
int p_[MAXN];
int p(int x) {
return p_[x] == x ? ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct A {
int x, id;
} a[N];
bool cmp(A x, A y) { return x.x < y.x; }
int a0[N], s[N], f[N], pre[N], nxt[N];
int f_f(int x) { return x == f[x] ? x : f[x] = f_f(f[x]); }
bool vv[N];
vector<int> t[N];
int main() {
int n, S;
scanf("%d%d", &n, &S);
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | java | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.Random;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, s, a[200020], b[200020], p[200020];
bool cmp(int i, int j) { return a[i] < a[j]; }
int rt[200020];
int findrt(int x) {
if (rt[x] != x) rt[x] = findrt(rt[x]);
return rt[x];
}
int get(int x) { return lower_bound(b + 1, b + n + 1, x) - b; }
map<int, int> S[200020];
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int gi() {
char ch = getchar();
int x = 0, q = 0;
while (ch < '0' || ch > '9') q = ch == '-' ? 1 : q, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return q ? -x : x;
}
int a[N], vis[N];
map<int, 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 = 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;
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 std::vector;
const int N = 300005;
int a[N], b[N], nt[N], t[N], n, cnt, now, s;
vector<int> ans[N];
int nxt(int x) {
while (nt[x] < t[x + 1] && a[nt[x]] == x) nt[x]++;
return nt[x];
}
void dfs(int x) {
if (nxt(x) < t[x + 1]) {
ans[now].push_back(nt[x]);
dfs(a[nt[x]++]);
}
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;
const int MAXN = 200228;
int nx[MAXN];
int p_[MAXN];
int p(int x) {
return p_[x] == x ? ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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;
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;
int main() {
int n, s;
cin >> n >> s;
int a[n + 1], b[n + 1], next[n + 1];
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
b[i] = a[i];
next[i] = i;
}
sort(b, b + n);
a[n] = b[n] = -1;
int cnt = 0;
vector<vector<int> > ans;
for (int i = 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 N = 4e5 + 10;
int Begin[N], Next[N], to[N], e;
void add(int u, int v) { to[++e] = v, Next[e] = Begin[u], Begin[u] = e; }
int n, m, k, c;
int A[N], rk[N], st[N], vis[N];
void DFS(int o) {
vis[o] = true;
for (int &i = Begin[o]; i;) {
int u = to[i];
i = 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 | 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;
using INT = long long;
using pii = pair<int, int>;
int a[200100];
int tmp[200100];
int vst[200100];
int rk[200100];
int flag[200100];
int st[200100];
vector<int> ans[200100];
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
int n, s;
cin >> n >> s;
for (int... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.