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 <bits/stdc++.h>
using namespace std;
#define pb push_back
#define nL '\n'
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
bool isWrong(int a, int b, int s) {
if (s == 1)
return a >= b;
return b >= a;
}
int main() {
#ifdef LOCAL
freopen("io/input.txt", "r", stdin);
freopen("io/output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int n, s;
cin >> n >> s;
vi a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vpii res;
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (isWrong(a[j], a[j+1], s)) {
res.pb({j+1, j});
a[j+1] = a[j]^a[j+1];
res.pb({j, j+1});
a[j] = a[j]^a[j+1];
res.pb({j+1, j});
a[j+1] = a[j]^a[j+1];
}
}
}
cout << res.size() << nL;
for (int i = 0; i < res.size(); i++)
cout << res[i].first+1 << " " << res[i].second+1 << nL;
return 0;
}
Compilation message (stderr)
xorsort.cpp: In function 'int main()':
xorsort.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 0; i < res.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... |