#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
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 |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
588 KB |
Output is correct |
5 |
Correct |
4 ms |
704 KB |
Output is correct |
6 |
Correct |
4 ms |
716 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
592 KB |
Output is correct |
9 |
Correct |
4 ms |
696 KB |
Output is correct |
10 |
Correct |
4 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
956 KB |
Output is correct |
13 |
Correct |
9 ms |
896 KB |
Output is correct |
14 |
Correct |
7 ms |
976 KB |
Output is correct |
15 |
Correct |
7 ms |
976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
588 KB |
Output is correct |
5 |
Correct |
4 ms |
704 KB |
Output is correct |
6 |
Correct |
4 ms |
716 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
592 KB |
Output is correct |
9 |
Correct |
4 ms |
696 KB |
Output is correct |
10 |
Correct |
4 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
956 KB |
Output is correct |
13 |
Correct |
9 ms |
896 KB |
Output is correct |
14 |
Correct |
7 ms |
976 KB |
Output is correct |
15 |
Correct |
7 ms |
976 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
4 ms |
592 KB |
Output is correct |
18 |
Correct |
8 ms |
848 KB |
Output is correct |
19 |
Correct |
6 ms |
860 KB |
Output is correct |
20 |
Correct |
6 ms |
848 KB |
Output is correct |
21 |
Correct |
6 ms |
832 KB |
Output is correct |
22 |
Correct |
6 ms |
848 KB |
Output is correct |
23 |
Correct |
6 ms |
848 KB |
Output is correct |
24 |
Correct |
6 ms |
848 KB |
Output is correct |
25 |
Correct |
6 ms |
828 KB |
Output is correct |
26 |
Incorrect |
11 ms |
1240 KB |
Integer 59568 violates the range [0, 40000] |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Not sorted |
2 |
Halted |
0 ms |
0 KB |
- |