#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1001;
int n;
int s;
vector<pair<int,int>>v;
int a[N];
vector<pair<int,int>>V;
void zameni(int i,int j){
v.push_back({i,j});
v.push_back({j,i});
v.push_back({i,j});
for(auto it:v)a[it.first]^=a[it.second];
for(auto it:v)V.push_back({it.first,it.second});
v.clear();
}
void Swap(int i,int j){
while(j>i){
zameni(j-1,j);
j--;
}
}
signed main(){
cin>>n>>s;
for(int i=1;i<=n;i++)cin>>a[i];
// kako da zamenim dva suseda ???
for(int i=1;i<=n;i++){
for(int j=i+1;j<=min(n,i+256);j++){
if(a[i]>a[j]){
Swap(i,j);
}
}
}
cout<<V.size();
cout<<endl;
for(auto it:V){
cout<<it.first<<" "<<it.second;
cout<<endl;
}
}
/*
5 1
3 2 8 4 1
*/
/*
max 40000 operacija
s=1 a[i]<a[i+1]
s=2 a[i]<=a[i+1]
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
20 ms |
724 KB |
Output is correct |
5 |
Correct |
25 ms |
980 KB |
Output is correct |
6 |
Correct |
20 ms |
980 KB |
Output is correct |
7 |
Correct |
20 ms |
980 KB |
Output is correct |
8 |
Correct |
25 ms |
980 KB |
Output is correct |
9 |
Correct |
22 ms |
980 KB |
Output is correct |
10 |
Correct |
23 ms |
984 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
40 ms |
1488 KB |
Output is correct |
13 |
Correct |
43 ms |
1488 KB |
Output is correct |
14 |
Correct |
40 ms |
1488 KB |
Output is correct |
15 |
Correct |
40 ms |
1488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
20 ms |
724 KB |
Output is correct |
5 |
Correct |
25 ms |
980 KB |
Output is correct |
6 |
Correct |
20 ms |
980 KB |
Output is correct |
7 |
Correct |
20 ms |
980 KB |
Output is correct |
8 |
Correct |
25 ms |
980 KB |
Output is correct |
9 |
Correct |
22 ms |
980 KB |
Output is correct |
10 |
Correct |
23 ms |
984 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
40 ms |
1488 KB |
Output is correct |
13 |
Correct |
43 ms |
1488 KB |
Output is correct |
14 |
Correct |
40 ms |
1488 KB |
Output is correct |
15 |
Correct |
40 ms |
1488 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
21 ms |
980 KB |
Output is correct |
18 |
Correct |
46 ms |
1236 KB |
Output is correct |
19 |
Correct |
36 ms |
1224 KB |
Output is correct |
20 |
Correct |
40 ms |
1232 KB |
Output is correct |
21 |
Correct |
36 ms |
1228 KB |
Output is correct |
22 |
Correct |
42 ms |
1232 KB |
Output is correct |
23 |
Correct |
37 ms |
1224 KB |
Output is correct |
24 |
Correct |
34 ms |
980 KB |
Output is correct |
25 |
Correct |
34 ms |
980 KB |
Output is correct |
26 |
Incorrect |
71 ms |
1788 KB |
Integer 59568 violates the range [0, 40000] |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
36 ms |
1168 KB |
Output is correct |
5 |
Incorrect |
650 ms |
12024 KB |
Integer 495234 violates the range [0, 40000] |
6 |
Halted |
0 ms |
0 KB |
- |