# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1044925 |
2024-08-05T14:39:08 Z |
mar |
Xor Sort (eJOI20_xorsort) |
C++14 |
|
41 ms |
1172 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[1000007];
int main(){
int n,s; cin>>n>>s;
for (int i = 0; i < n; i++){
cin>>arr[i];
}
vector<pair<int,int>> ans;
if(s==2){
for(int bit = 22; bit >= 0; bit--){
for(int i = 0; i+1 < n; i++){
if(arr[i]&(1LL<<bit)){
if (arr[i+1]&(1LL<<bit)){
ans.push_back({i+1,i+2});
arr[i]^=arr[i+1];
} else {
ans.push_back({i+2,i+1});
ans.push_back({i+1,i+2});
arr[i+1]^=arr[i];
arr[i]^=arr[i+1];
}
}
}
if((n>=1) && (arr[n-1]&(1LL<<bit))){
n--;
}
}
} else {
for(int i = n; i >= 1; i--){
int mx = 0;
for(int j = 0; j < i; j++){
if(arr[j]>arr[mx]) mx=j;
if(j+1<i){
ans.push_back({j+1,j+2});
}
}
for(int j = mx-2; j >= 0; j--){
ans.push_back({j+1,j+2});
}
for(int j = mx; j+1 < i; j++){
ans.push_back({j+2,j+1});
}
for(int k = mx; k + 1 < i; k++){
swap(arr[k],arr[k+1]);
}
}
for(int i = n; i >= 2; i--){
ans.push_back({i-1,i});
}
}
cout<<ans.size()<<endl;
for (int i = 0; i < ans.size(); i++){
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}
}
Compilation message
xorsort.cpp: In function 'int main()':
xorsort.cpp:54: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]
54 | for (int i = 0; i < ans.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
33 ms |
796 KB |
Output is correct |
5 |
Correct |
20 ms |
724 KB |
Output is correct |
6 |
Correct |
19 ms |
856 KB |
Output is correct |
7 |
Correct |
20 ms |
728 KB |
Output is correct |
8 |
Correct |
20 ms |
848 KB |
Output is correct |
9 |
Correct |
21 ms |
728 KB |
Output is correct |
10 |
Correct |
20 ms |
868 KB |
Output is correct |
11 |
Correct |
21 ms |
980 KB |
Output is correct |
12 |
Correct |
20 ms |
728 KB |
Output is correct |
13 |
Correct |
20 ms |
820 KB |
Output is correct |
14 |
Correct |
20 ms |
816 KB |
Output is correct |
15 |
Correct |
20 ms |
792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
33 ms |
796 KB |
Output is correct |
5 |
Correct |
20 ms |
724 KB |
Output is correct |
6 |
Correct |
19 ms |
856 KB |
Output is correct |
7 |
Correct |
20 ms |
728 KB |
Output is correct |
8 |
Correct |
20 ms |
848 KB |
Output is correct |
9 |
Correct |
21 ms |
728 KB |
Output is correct |
10 |
Correct |
20 ms |
868 KB |
Output is correct |
11 |
Correct |
21 ms |
980 KB |
Output is correct |
12 |
Correct |
20 ms |
728 KB |
Output is correct |
13 |
Correct |
20 ms |
820 KB |
Output is correct |
14 |
Correct |
20 ms |
816 KB |
Output is correct |
15 |
Correct |
20 ms |
792 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
20 ms |
836 KB |
Output is correct |
18 |
Correct |
34 ms |
1080 KB |
Output is correct |
19 |
Correct |
41 ms |
984 KB |
Output is correct |
20 |
Correct |
36 ms |
984 KB |
Output is correct |
21 |
Correct |
37 ms |
984 KB |
Output is correct |
22 |
Correct |
35 ms |
984 KB |
Output is correct |
23 |
Correct |
35 ms |
984 KB |
Output is correct |
24 |
Correct |
35 ms |
984 KB |
Output is correct |
25 |
Correct |
35 ms |
984 KB |
Output is correct |
26 |
Correct |
35 ms |
984 KB |
Output is correct |
27 |
Correct |
35 ms |
984 KB |
Output is correct |
28 |
Correct |
38 ms |
984 KB |
Output is correct |
29 |
Correct |
37 ms |
1172 KB |
Output is correct |
30 |
Correct |
36 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
5 ms |
580 KB |
Output is correct |
5 |
Correct |
28 ms |
1028 KB |
Output is correct |
6 |
Correct |
26 ms |
984 KB |
Output is correct |
7 |
Correct |
27 ms |
1008 KB |
Output is correct |
8 |
Correct |
27 ms |
928 KB |
Output is correct |
9 |
Correct |
26 ms |
984 KB |
Output is correct |
10 |
Correct |
27 ms |
984 KB |
Output is correct |
11 |
Correct |
27 ms |
940 KB |
Output is correct |
12 |
Correct |
29 ms |
984 KB |
Output is correct |
13 |
Correct |
29 ms |
924 KB |
Output is correct |
14 |
Correct |
28 ms |
1068 KB |
Output is correct |
15 |
Correct |
36 ms |
984 KB |
Output is correct |