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 |
|---|---|---|---|---|---|---|
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | def palin():
for i in xrange(input()):
lst=raw_input()
lst=list(lst)
b=lst[::-1]
if b==lst:
print "YES"
else:
for i in xrange(len(lst)):
if b[i]!=lst[i]:
c=b[::1];d=lst[::1]
del c[i];del d[len(ls... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | #!/usr/bin/py
t=raw_input()
def pal(s):
sl=len(s)
for l1 in range(0,sl/2+(sl%2)):
if s[l1]!=s[sl-l1-1]:
return 0
return 1
for l in range(0,int(t)):
s=raw_input()
r=len(s)
flag=0
for l1 in range(0,len(s)/2+(len(s)%2)):
if s[l1]!= s[r-1]:
c1=pal(s[l1+1:r])
c2=pal(s... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | def isPal(s):
l=len(s)
for x in xrange(l/2):
if s[x]!=s[-1-x]:
return False
return True
def isPos():
s=raw_input()
n=len(s)
for i in xrange(n/2):
if s[i]!=s[n-1-i]:
if isPal(s[i:n-1-i]) or isPal(s[i+1:n-i]):
return "YES"
else:
... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | t=int(raw_input())
while t>0:
s=raw_input()
length=len(s)
i=0
j=length-1
counter=0
while(i<j):
if(s[i]!=s[j]):
counter+=1
i+=1
else:
i+=1
j-=1
if(counter<=1):
print "YES"
else:
i=0
j=length-1
... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | def check(s,x):
n=len(s)
if (s==s[::-1]):
return 1
else:
if (x==0):
for i in range(n):
if (s[i]!=s[n-i-1]):
t=s[:i]+s[i+1:]
u=s[:n-i-1]+s[n-i:]
return (check(t,1) or check(u,1))
else:
return 0
for t in range(int(raw_input())):
s=raw_input()
if (check(s,0)):
print "YES"
else:
pri... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | t=input()
while t>0:
t-=1
s=raw_input()
i,j=0,len(s)-1
lim=0
while i<j:
if s[i]!=s[j]:
lim+=1
if s[i]==s[j-1]:
k,l=i,j-1
flag=0
while k<l:
if s[k]!=s[l]:
flag=1
break
k+=1
l-=1
if(flag==0):
break
if s[i+1]==s[j]:
k,l=i+1,j
flag=0
while k<l:
... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | def check_palindrome(s):
#s = list(s)
l = len(s)
j = l-1
for i in range(l/2):
if s[i] != s[j]:
return False
j = j-1
return True
#if (__name__ == "__main__"):
if(True):
t = raw_input()
t = int(t)
for i in range(t):
s = raw_input()
l = len(s)
y = 0
j = l-1
cnt = 0
for k in range(l/2):
if(s[... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | t = input()
while(t>0):
t = t-1
s = raw_input()
length = len(s)
if(length==2):
print "YES"
continue
freq = [0]*26
for x in (s):
pos=ord(x)
freq[pos-97] = freq[pos-97]+1
evenfreq=0
oddfreq=0
diffcharfreq=0
for x in range(0,26):
... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | def check_palin(val, i, j):
flag = False
while i < j:
if val[i] != val[j]:
flag = True
break
i += 1
j -= 1
if flag:
return (i, j)
return (-1, -1)
def process():
val = raw_input()
i, j = check_palin(val, 0, len(val)-1)
if i == -1 or j ... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | for _ in range(int(raw_input())):
s=list(raw_input())
s1c=list(s)
s2c=list(s)
n=len(s)
flag=0
for i in range(n/2):
if s[i]!=s[n-1-i]:
del s1c[i]
if s1c==s1c[::-1]:
print "YES"
flag=1
break
del s2c[n-1-i]
... |
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string... | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | import sys
for __ in range(input()) :
a=list(raw_input())
answered=False
s=[i for i in reversed(a)]
for i in range(len(s)) :
if s[i]!=a[i] :
s.pop(i)
a.pop(i)
#print s,a
if s==s[::-1] or a==a[::-1] :
print "YES"
an... |
tf01 | An established group of scientists are working on finding solution to NP hard problems. They claim Subset Sum as an NP-hard problem. The problem is to determine whether there exists a subset of a given set S whose sum is a given number K.
You are a computer engineer and you claim to solve this problem given that all... | {
"input": [
"2\n5 10\n3 4 6 1 9\n3 2\n1 3 4"
],
"output": [
"1\n0"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | import sys
for __ in range(input()) :
n , k = map(int,sys.stdin.readline().split())
lists = map(int,sys.stdin.readline().split())
dp = [0]*(k+1)
dp[0]=1
for i in lists :
for j in range(k-i,-1,-1) :
if dp[k] :
break
if dp[j] :
dp[j+i] =... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;
map<int, int> mapa;
map<pair<int, int>, vector<int>> pos;
vector<int> g[MAXN];
int ptr[MAXN];
int used[MAXN];
void euler(int v, vector<int> &res) {
used[v] = true;
for (; ptr[v] < (int)(g[v]).size();) {
++ptr[v];
int u = g[v][ptr[v] - 1]... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | 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... | 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... | 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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, s, a[200005], b[200005], c[200005], vis[200005], wa, cir, prn[200005],
to[200005], nex[200005], beg[200005], val[200005], e;
bool acs[200005];
void insert(int x, int y, int z) {
to[++e] = y;
nex[e] = beg[x];
beg[x] = e;
val[e] = z;
}
vector<int> tek[20000... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, S;
int a[N], p[N], q[N];
vector<vector<int>> cir;
int uf[N];
int find(int x) { return (uf[x] == x) ? (x) : (uf[x] = find(uf[x])); }
void adjust() {
for (int i = 1; i <= n; i++) {
uf[i] = i;
}
pair<int, int>* b = new pair<int, int>[(n ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int n, limit;
int nxt[N], lab[N], flag[N];
pair<int, int> a[N];
vector<int> ans1, ans2;
vector<vector<int> > ans3;
vector<pair<int, int> > v;
int root(int u) {
if (lab[u] < 0) return u;
return lab[u] = root(lab[u]);
}
void join(int u, int v) {
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)2e5 + 3;
const int infint = (int)1e9 + 3;
const long long inf = (long long)1e17;
int n, s, a[MAXN], idx[MAXN], final[MAXN], par[MAXN], visited[MAXN];
set<int> id[MAXN], num[MAXN];
vector<int> cyc[MAXN];
bool cmp(int u, int v) { return a[u] < a[v]; }
in... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while ('0' > ch || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
con... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int n, m;
int a[N + 1];
vector<int> nums;
void discrete() {
sort(nums.begin(), nums.end());
nums.resize(unique(nums.begin(), nums.end()) - nums.begin());
for (int i = 1; i <= n; i++)
a[i] = lower_bound(nums.begin(), nums.end(), a[i]) - nums.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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
struct ln {
int val;
ln* next;
};
vector<pair<int, int> >* nl;
vector<pair<int, int> > ar;
int* roi;
bool* btdt;
ln* fe(ln* ath, int cp) {
ln* sv = NULL;
ln* ov = NULL;
for (int i = roi[cp]; i < nl[cp].size(); i = roi[cp]) {
int np = nl[cp][i].first;
int i... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 200600;
int n, S;
int a[N];
int b[N];
int xs[N];
int k;
vector<int> g[N];
int m;
vector<int> cycles[N];
int p[N];
bool used[N];
void dfs(int v) {
while (!g[v].empty()) {
int id = g[v].back();
g[v].pop_back();
dfs(a[id]);
cycles[m].push_back(i... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using std::lower_bound;
using std::max;
using std::min;
using std::random_shuffle;
using std::reverse;
using std::sort;
using std::swap;
using std::unique;
using std::upper_bound;
using std::vector;
void open(const char *s) {}
int rd() {
int s = 0, c, b = 0;
while (((c = getchar()) < '0' ||... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
int a[maxn], b[maxn], nxt[maxn];
pair<int, int> srt[maxn];
map<int, vector<int> > mp;
vector<vector<int> > ans;
int par[maxn], who[maxn];
int fnd(int u) { return par[u] < 0 ? u : par[u] = fnd(par[u]); }
v... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n, m;
const int N = 2e5 + 5;
int a[N], b[N], p[N], vis[N], cnt, head[N], fa[N], ins[N], ok[N];
vector<int> V, tmp;
struct edg {
int to, nxt, w;
} e[N];
void add(int u, int v, int w) {
cnt++;
e[cnt].to = v;
e[cnt].nxt = head[u];
head[u] = cnt;
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[200000];
int nxt[200000];
bool v[200000];
vector<int> cycle;
void dfs(int now) {
v[now] = true;
while (nxt[now] < adj[now].size()) {
nxt[now]++;
dfs(adj[now][nxt[now] - 1].first);
}
cycle.push_back(now);
}
void dfs2(int now) {
v... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 202020;
int N, S, val[MAXN], sorted[MAXN], begin_idx[MAXN], incl[MAXN], c = 0;
map<int, int> compress;
vector<int> adj[MAXN], cycle;
map<pair<int, int>, vector<int>> locs;
void recur(int n) {
;
while (adj[n].size() > 0) {
int nex = adj[n].back();
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 239;
int n, s, a[M], p[M];
pair<int, int> b[M];
int parent[M], r[M];
inline void init() {
for (int i = 0; i < n; i++) {
parent[i] = i;
r[i] = 0;
}
}
inline int find_set(int p) {
if (parent[p] == p) return p;
return (parent[p] = find_set(p... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, a[N], K, sum;
map<int, int> mp;
map<int, vector<int> > g;
vector<vector<int> > ans;
vector<int> vec;
inline void dfs(const int x) {
register int i;
while (!g[x].empty())
i = g[x].back(), g[x].pop_back(), dfs(a[i]), vec.push_back(i);
g... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using cat = long long;
void DFS(int R, vector<vector<int> >& G, vector<bool>& vis, vector<int>& cyc) {
vis[R] = true;
while (!G[R].empty()) {
int v = G[R].back();
G[R].pop_back();
DFS(v, G, vis, cyc);
}
cyc.push_back(R);
}
int main() {
cin.sync_with_st... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
vector<int> pat[500000];
vector<int> rev[500000];
vector<bool> flag[500000];
int pt[500000];
void adde(int a, int b) {
pat[a].push_back(b);
flag[a].push_back(false);
}
vector<int> euler;
void calceuler(int node) {
for (;;) {
if (pt[node] == pat[node].size()) break... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MN = 200010;
int fa[MN];
void init() {
for (int i = 0; i < MN; i++) fa[i] = i;
}
int find(int u) {
if (fa[u] == u)
return u;
else
return fa[u] = find(fa[u]);
}
void mrg(int u, int v) {
u = find(u);
v = find(v);
if (u == v) return;
fa[v] = u;
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int a[200000], b[200000];
vector<int> pos[200000];
int p[200000], nxt[200000];
int parent[200000];
int find(int n) {
if (parent[n] != n) parent[n] = find(parent[n]);
return parent[n];
}
int visited[200000];
vector<int> cycles[200000];
int main() {
int i;
int n, s;
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, K;
map<int, int> Map;
int A[201000], B[201000], w[201000];
vector<int> GG[201000];
int GPV[201000];
int tA[201000];
vector<int> G;
int UF[201000], sss;
int Find(int a) {
if (a == UF[a]) return a;
return UF[a] = Find(UF[a]);
}
void Merge(int a, int b) {
a = Find... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
struct UF {
int n;
vector<int> par;
UF(int n) : n(n) {
for (int i = 0; i < n; i++) par.push_back(i);
}
int find(int a) {
if (a != par[a]) par[a] = find(par[a]);
return par[a];
}
void join(int a, int b) { par[find(a)] = find(b); }
};
struct V {
ve... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
const int MAX_N = 200000;
int v[1 + MAX_N], poz[1 + MAX_N], sorted[1 + MAX_N];
bool cmp(int a, int b) { return v[a] < v[b]; }
std::vector<int> src[1 + MAX_N], target[1 + MAX_N];
void normalize(int n) {
std::sort(poz + 1, poz + 1 + n, cmp);
int last = v[poz[1]], j = 1;
for (int i = 1; i <=... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
unordered_map<int, int> mp;
int a[N], b[N], he[N], to[N], ne[N], c;
basic_string<int> w[N];
bool v[N];
void dfs(int x) {
v[x] = 1;
for (int i; i = he[x];) he[x] = ne[i], dfs(to[i]), w[c] += i;
}
int main() {
int t = 0, i, j, k, n, s;
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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const long long int INF = 1e18 + 9LL;
int n, s;
int in[N];
int last[N];
int sorted[N];
set<int> place[N];
set<int> value[N];
int cnt;
map<int, int> M;
int dir[N];
bool vis[N];
vector<int> cur;
void solve(int c) {
if (place[c]... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], n, s, b[maxn], num[maxn], len;
int ufs[maxn], meme[maxn];
inline int find(int u) {
if (ufs[u] == u)
return u;
else
return ufs[u] = find(ufs[u]);
}
inline void join(int u, int v, int e) {
u = find(u), v = find(v);
if (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... | 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... | 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 solve(int[] a, int s) {
int n = 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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, s, a[200079], p[200079];
vector<pair<int, int> > b(200079);
int rodic[200079], r[200079];
int najdisef(int v) {
if (rodic[v] == v) return v;
rodic[v] = najdisef(rodic[v]);
return rodic[v];
}
void spojset(int i, int j) {
i = najdisef(i);
j = najdisef(j);
i... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int b[N], t[N], nt[N], u;
vector<int> ans[N];
int top;
int NT(int x) {
while (nt[x] < t[x + 1] && a[nt[x]] == x) ++nt[x];
return nt[x];
}
void dfs(int x) {
while (NT(x) < t[x + 1]) {
int now = nt[x]++;
dfs(a[now]);
ans[top]... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
if (a < b) a = b;
}
const int MAXN = 400013;
int N, S, M, ans, n;
int val[MAXN], arr[MAXN], sorted[MAXN];
vector<int> moves[MAXN];
vector<int> cyc... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename S, typename T>
void xmin(S &a, T const &b) {
if (b < a) a = b;
}
template <typename S, typename T>
void xmax(S &a, T const &b) {
if (b > a) a = b;
}
vector<vector<pair<int, int> > > g;
vector<int> eu;
vector<int> cured;
void rec(... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
int arr[MAXN], tmp[MAXN];
vector<int> ve[MAXN];
map<pair<int, int>, vector<int> > mapa;
int ind[MAXN];
vector<int> out[MAXN];
int sol = 0;
vector<int> t1, t2;
vector<int> comp;
map<int, int> aaa;
void tour(int x, int i) {
while (ind[x] < ve[x].siz... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
const int N = 2e5 + 5;
int n, s, cnt, to[N], a[N], b[N], pos[N];
vector<int> all[N];
pair<int, int> p[N];
vo... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
const int NN = 200011;
int a[NN], b[NN], arr[NN];
VI vec[NN], cyc[NN];
int nc;
int dp[NN], vst[NN];
int n, s;
void dfs(int u) {
while (not vec[u].empty()) {
int v = vec[u].back();
vec[u].pop_back();
dfs(a[v]);
cyc[nc].push_back(v);
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
if (a < b) a = b;
}
const int MAXN = 400013;
int N, S, M, ans, n;
int val[MAXN], arr[MAXN], sorted[MAXN];
vector<int> moves[MAXN];
vector<int> cyc... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 10;
int to[sz], pr[sz], si[sz], cyq = 0;
bool us[sz];
vector<int> cy[sz];
int find_se(int v) {
if (v != pr[v]) pr[v] = find_se(pr[v]);
return pr[v];
}
void merge(int u, int v) {
u = find_se(u), v = find_se(v);
if (u != v) {
if (si[v] > si[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... | CORRECT | cpp | #include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
const int MAXN = 210000;
int was[MAXN];
int wss[MAXN];
vector<int> st;
vector<vector<int>> vv;
vector<vector<int>> vv2;
int lb[MAXN];
int rb[MAXN];
set<int> ss;
int pl[MAXN], cl[MAXN];
int pos[MAXN];
int n;
void dfs1(int v) {
was[v] = 1;
st.pu... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int N, S;
int A[200020], B[200020];
vector<int> vx;
int pp[200020];
int Find(int x) { return pp[x] == x ? x : pp[x] = Find(pp[x]); }
vector<int> vs[2][200020];
int nxt[200020];
int main() {
scanf("%d%d", &N, &S);
for (int i = 1; i <= N; i++) scanf("%d", A + i);
for (i... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, S, a[200010], fa[200010];
inline int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); }
inline void merge(int x, int y) {
x = getf(x);
y = getf(y);
if (x != y) fa[x] = y;
}
pair<int, int> p[200010];
class node {
public:
int vl, pos, id;
bool oper... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
int n, s;
int a[maxn], b[maxn];
int idx[maxn];
bool CmpI(int i, int j) { return a[i] < a[j]; }
int p[maxn];
int Find(int x) { return x == p[x] ? x : p[x] = Find(p[x]); }
void Unite(int x, int y) { p[Find(x)] = Find(y); }
int _1[maxn], _2[maxn];
void Pr... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
vector<bool> vis;
vector<pair<long long, long long>> eulerWalk(
vector<vector<pair<long long, long long>>>& gr, vector<long long>& eu,
int src, vector<long long>& D, vector<long long>& its) {
vector<pair<long long, long long>> ret, s = ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010], nxt[200010];
bool vis[200010];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, s;
cin >> n >> s;
for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
sort(b + 1, b + n + 1);
vector<int> v;
for (int i = 1; i <= n; i++)
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void ckmax(T& x, T y) {
x = (y > x ? y : x);
}
template <typename T>
inline void ckmin(T& x, T y) {
x = (y < x ? y : x);
}
const int MAXN = 2e5;
int n, lim, a[MAXN + 5], goal[MAXN + 5];
int vals[MAXN + 5], cnt_val;
int need_oper_pos;
vector<... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int dsu[N];
int rang[N];
int pred(int a) {
if (a == dsu[a]) return a;
return dsu[a] = pred(dsu[a]);
}
void unite(int a, int b) {
a = pred(a);
b = pred(b);
if (a != b) {
if (rang[a] < rang[b]) {
swap(a, b);
}
dsu[b] = a;
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | 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];
int siz = 0;
void dfs(int x) {
bio[x] = 1;
while (!graf[x].empty()) {
i... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7;
const long double eps = 1e-8;
mt19937_64 randGen(system_clock().now().time_since_epoch().count());
inline void raiseError(string erro... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int N, S, cnt;
int A[200005], A2[200005];
bool Use[200005];
int P[200005];
map<int, int> X;
int cyc, R[200005], TT[200005];
vector<int> V[200005], Cycle[200005];
void Read() {
scanf("%d%d", &N, &S);
for (int i = 1; i <= N; i++) {
scanf("%d", &A[i]);
A2[i] = A[i]... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int const MAX = 4e5 + 41;
int n, s;
int a[MAX];
int b[MAX];
int c[MAX];
vector<int> e[MAX];
vector<vector<int> > ans;
set<int> poses[MAX];
int cnt;
int u[MAX];
int lp[MAX];
int rp[MAX];
vector<int> getposes(vector<int> st) {
reverse(st.begin(), st.end());
vector<int> re... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, K, a[200100];
map<int, int> mp1;
map<int, vector<int> > mp2;
vector<vector<int> > ans;
vector<int> vec;
void dfs(int x) {
for (int i; !mp2[x].empty(); vec.push_back(i)) {
i = mp2[x].back();
mp2[x].pop_back();
dfs(a[i]);
}
mp2.erase(x);
}
int main() ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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... | 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... | 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... | CORRECT | java | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Random;
import java.util.ArrayList;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, s, 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, neg = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') neg = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
return x * neg;
}
inline int qpow(int x, int e, int _MOD) {
int ans = 1;
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | 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... | 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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct fastio {
char s[100000];
int it, len;
fastio() { it = len = 0; }
inline char get() {
if (it < len) return s[it++];
it = 0;
len = fread(s, 1, 100000, stdin);
if (len == 0)
return EOF;
else
return s[it++]... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7;
const long double eps = 1e-8;
mt19937_64 randGen(system_clock().now().time_since_epoch().count());
inline void raiseError(string erro... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | 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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
inline int rint() {
int x = 0;
char s = getchar();
for (; s < '0' || '9' < s; s = getchar())
;
for (; '0' <= s && s <= '9'; s = getchar()) x = x * 10 + (s ^ '0');
return x;
}
template <typename Tp>
inline void wint(Tp x) {
if (x < 0) putchar('-'), x = -x;
if (9 < x) wint(x / 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... | CORRECT | cpp | #include <bits/stdc++.h>
int n, s, a[200010], b[200010], nums[200010], cnt, fa[200010];
int find(int i) { return fa[i] == i ? i : fa[i] = find(fa[i]); }
bool tag[200010];
struct edge {
int to;
edge* next;
} E[200010], *fir[200010];
std::vector<int> C[200010];
void dfs(int i, int t) {
while (fir[i]) {
edge* e ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 20;
int arr[MAXN], srt[MAXN];
bool bio[MAXN];
vector<pair<int, int>> edges[MAXN];
vector<vector<int>> cyc;
void euler(int i) {
bio[i] = true;
while (!edges[i].empty()) {
auto x = edges[i].back();
edges[i].pop_back();
euler(x.first);
... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int A[200005], B[200005], Q[200005];
pair<int, int> P[200005];
vector<int> getcycle(int x) {
int init = x;
vector<int> ret;
do {
ret.push_back(x);
x = Q[x];
} while (x != init);
return ret;
}
int par[200005], pos[200005];
int root(int a) {
if (par[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... | 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... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int a[200010], p[200010], n, s;
pair<int, int> b[200010];
int fa[200010], r[200010];
int get_fa(int x) {
if (fa[x] == 0) return x;
fa[x] = get_fa(fa[x]);
return fa[x];
}
void merge(int x, int y) {
int fx = get_fa(x);
int fy = get_fa(y);
if (fx != fy) fa[fx] = fy... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int M = 0, fst[666666], vb[666666], nxt[666666], vc[666666];
void ad_de(int a, int b, int c) {
++M;
nxt[M] = fst[a];
fst[a] = M;
vb[M] = b;
vc[M] = c;
}
void adde(int a, int b, int c) {
ad_de(a, b, c);
ad_de(b, a, c);
}
map<int, int> vis;
int n, s, a[666666], ... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n, m, a[200010], b[200010], x[200010], y[200010], f[200010], r[200010],
c[200010], p, d[200010], q;
map<int, int> h;
inline int fa(int i) { return f[i] == i ? i : f[i] = fa(f[i]); }
inline void unit(int i, int j) {
i = fa(i);
j = fa(j);
if (i != j) f[i] = j;
}... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char buf[25];
const int maxn = 200010;
struct node {
int w, id;
} c[maxn], d[maxn];
vector<int> v[maxn];
int a[maxn], b[maxn], f[maxn], q[maxn];
bool p[maxn];
int n, m, s, ans;
int read() {
int x = 0, f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160000")
using namespace std;
void redirectIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
int n;
int a[210000];
map<int, vector<int>> numberPositions;
int s;
int sa[210000];
int badPos;
vector<vector<int>> vectors;
bool vis[210000];
int goesTo[210000... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int n = 0;
char c;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
;
for (; c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - 48;
return n;
}
const int maxn = 2e5 + 5;
int i, j, n, s, a[maxn], f[maxn], p[maxn], cnt, sum;
vector<i... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
using ll = int64_t;
using Pii = pair<int, int>;
using ull = uint64_t;
using Vi = vector<int>;
void run();
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
run();
return 0;
}
vector<vector<Pii>> G;
vector<... |
1012_E. Cycle sort | You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t... | {
"input": [
"5 5\n3 2 3 1 1\n",
"4 3\n2 1 4 3\n",
"2 0\n2 2\n"
],
"output": [
"1\n5\n1 4 2 3 5 \n",
"-1\n",
"0\n"
]
} | {
"input": [
"5 0\n884430748 884430748 708433020 708433020 708433020\n",
"2 1\n1 1\n",
"2 0\n2 1\n",
"5 2\n65390026 770505072 65390026 65390026 65390026\n",
"5 4\n812067558 674124159 106041640 106041640 674124159\n",
"5 4\n167616600 574805150 651016425 150949603 379708534\n",
"5 5\n4727783... | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.