This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int get(vector<int> a,int target){
for(int i = 0;i<a.size();i++){
if(a[i] == target)
return i;
}
assert(0);
}
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
if(is_sorted(s,s+n))
return 0;
for(int i = 0;i<m;i++){
p[i] = q[i] = 0;
}
vector<int> fnal;
vector<int> now;
for(int i = 0;i<n;i++){
fnal.push_back(s[i]);
now.push_back(s[i]);
}
for(int i = 0;i<m;i++){
swap(fnal[x[i]],fnal[y[i]]);
}
for(int i = 0;i<m;i++){
swap(now[x[i]],now[y[i]]);
if(i < n){
int ps1 = get(now,i);
int ps2 = get(now,fnal[i]);
p[i] = ps1;
q[i] = ps2;
swap(now[ps1],now[ps2]);
swap(fnal[i],fnal[get(fnal,i)]);
}
if(is_sorted(now.begin(),now.end()))
return i+1;
}
assert(0);
}
Compilation message (stderr)
sorting.cpp: In function 'int get(std::vector<int>, int)':
sorting.cpp:5:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | for(int i = 0;i<a.size();i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |