#include<iostream>
#include<vector>
#include<algorithm>
#define endl '\n'
using namespace std;
int n,s,p[1005];
pair<int,int> m[1005];
vector< pair<int,int> > v;
bool cmp(pair<int,int> a, pair<int,int> b)
{
return a.first>b.first;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>s;
for(int i=1;i<=n;i++){
cin>>m[i].first;
m[i].second=i;
}
if(s==2){
for(int i=1;i<=(1<<20);i*=2)
{
for(int j=1;j<n;j++)
{
if((i&m[j].first))
{
if(!(i&m[j+1].first))
{
v.push_back({j+1,j});
m[j+1].first^=m[j].first;
}
v.push_back({j,j+1});
m[j].first^=m[j+1].first;
}
}
}
}
if(s==1){
sort(m+1,m+n+1,cmp);
int t;
for(int i=1;i<=n;i++)
{
t=m[i].second-p[m[i].second];
for(int j=m[i].second+1;j<=n;j++) p[j]++;
for(int j=1;j<=min(n-1,n-i+1);j++)
{
v.push_back({j,j+1});
}
for(int j=t+1;j<=n-i+1;j++)
{
v.push_back({j,j-1});
}
for(int j=t-2;j>=1;j--)
{
v.push_back({j,j+1});
}
}
}
cout<<v.size()<<endl;
for(int i=0;i<v.size();i++)
{
cout<<v[i].first<<" "<<v[i].second<<endl;
}
}
Compilation message
xorsort.cpp: In function 'int main()':
xorsort.cpp:72:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
5 ms |
720 KB |
Output is correct |
5 |
Correct |
6 ms |
712 KB |
Output is correct |
6 |
Correct |
5 ms |
720 KB |
Output is correct |
7 |
Correct |
5 ms |
720 KB |
Output is correct |
8 |
Correct |
5 ms |
720 KB |
Output is correct |
9 |
Correct |
5 ms |
720 KB |
Output is correct |
10 |
Correct |
5 ms |
720 KB |
Output is correct |
11 |
Correct |
5 ms |
720 KB |
Output is correct |
12 |
Correct |
5 ms |
752 KB |
Output is correct |
13 |
Correct |
5 ms |
720 KB |
Output is correct |
14 |
Correct |
5 ms |
720 KB |
Output is correct |
15 |
Correct |
5 ms |
720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
5 ms |
720 KB |
Output is correct |
5 |
Correct |
6 ms |
712 KB |
Output is correct |
6 |
Correct |
5 ms |
720 KB |
Output is correct |
7 |
Correct |
5 ms |
720 KB |
Output is correct |
8 |
Correct |
5 ms |
720 KB |
Output is correct |
9 |
Correct |
5 ms |
720 KB |
Output is correct |
10 |
Correct |
5 ms |
720 KB |
Output is correct |
11 |
Correct |
5 ms |
720 KB |
Output is correct |
12 |
Correct |
5 ms |
752 KB |
Output is correct |
13 |
Correct |
5 ms |
720 KB |
Output is correct |
14 |
Correct |
5 ms |
720 KB |
Output is correct |
15 |
Correct |
5 ms |
720 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
5 ms |
720 KB |
Output is correct |
18 |
Correct |
8 ms |
976 KB |
Output is correct |
19 |
Correct |
8 ms |
976 KB |
Output is correct |
20 |
Correct |
8 ms |
956 KB |
Output is correct |
21 |
Correct |
8 ms |
976 KB |
Output is correct |
22 |
Correct |
8 ms |
1008 KB |
Output is correct |
23 |
Correct |
11 ms |
1004 KB |
Output is correct |
24 |
Correct |
8 ms |
976 KB |
Output is correct |
25 |
Correct |
9 ms |
988 KB |
Output is correct |
26 |
Correct |
8 ms |
976 KB |
Output is correct |
27 |
Correct |
8 ms |
976 KB |
Output is correct |
28 |
Correct |
8 ms |
976 KB |
Output is correct |
29 |
Correct |
8 ms |
976 KB |
Output is correct |
30 |
Correct |
8 ms |
976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
7 ms |
888 KB |
Output is correct |
6 |
Correct |
8 ms |
860 KB |
Output is correct |
7 |
Correct |
6 ms |
836 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
7 ms |
848 KB |
Output is correct |
10 |
Correct |
6 ms |
848 KB |
Output is correct |
11 |
Correct |
6 ms |
848 KB |
Output is correct |
12 |
Correct |
7 ms |
972 KB |
Output is correct |
13 |
Correct |
7 ms |
848 KB |
Output is correct |
14 |
Correct |
7 ms |
924 KB |
Output is correct |
15 |
Correct |
8 ms |
976 KB |
Output is correct |