#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
int pas[40005][3];
int a[2000002];
pair<int,int> aa[2000002];
int a1[2000002];
int n;
int main(){
int s;
cin>>n;
cin>>s;
int k=0;
for(int i=1; i<=n; i++){
cin>>a[i];
a1[i]=a[i];
aa[i].f=a[i];
aa[i].s=i;
}
sort(aa+1, aa+n+1);
int lastsort=n;
while(lastsort!=1){
int maxi=aa[lastsort].s;
//cout<<lastsort;
// cout<<aa[3].s<<endl;
//cout<<maxi<<"maxi"<<endl;
for(int i=1; i<=lastsort-1; i++ ){
k++;
pas[k][1]=i;
pas[k][2]=i+1;
// cout<<a1[i]<<" "<<a1[i+1]<<" "<<a[i]<<"cri1"<<endl;
a1[i]=a1[i]^a1[i+1];
// cout<<a1[i]<<" "<<a1[i+1]<<" "<<a[i]<<"crine1"<<endl;
}
for(int i=maxi+1; i<=lastsort; i++){
k++;
pas[k][1]=i;
pas[k][2]=i-1;
// cout<<a1[i]<<" "<<a1[i-1]<<" "<<a[i]<<"cri2"<<endl;
a1[i]=a1[i]^a1[i-1];
// cout<<a1[i]<<" "<<a1[i-1]<<" "<<a[i]<<"crine2"<<endl;
}
for(int i=maxi-2; i>=1; i--){
k++;
pas[k][1]=i;
pas[k][2]=i+1;
// cout<<a1[i]<<" "<<a1[i+1]<<" "<<a[i]<<"cri3"<<endl;
a1[i]=a1[i]^a1[i+1];
// cout<<a1[i]<<" "<<a1[i+1]<<" "<<a[i]<<"crine3"<<endl;
}
// cout<<a1[lastsort]<<" cr "<<endl;
for(int i=1; i<=n; i++){
if(aa[i].s>maxi){
aa[i].s--;
}
// aa[maxi].s=lastsort;
}
lastsort--;
}
for(int i=n-1; i>=1; i--){
k++;
pas[k][1]=i;
pas[k][2]=i+1;
a1[i]=a1[i]^a1[i+1];
}
cout<<k<<endl;
for(int i=1; i<=k; i++){
cout<<pas[i][1]<<" "<<pas[i][2]<<endl;
}
/*
cout<<endl;
for(int i=1; i<=n; i++){
cout<<a1[i]<<" ";
}
*/
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
292 KB |
Output is correct |
4 |
Correct |
27 ms |
664 KB |
Output is correct |
5 |
Correct |
28 ms |
668 KB |
Output is correct |
6 |
Correct |
29 ms |
700 KB |
Output is correct |
7 |
Correct |
32 ms |
588 KB |
Output is correct |
8 |
Correct |
28 ms |
672 KB |
Output is correct |
9 |
Correct |
27 ms |
676 KB |
Output is correct |
10 |
Correct |
29 ms |
696 KB |
Output is correct |
11 |
Correct |
28 ms |
652 KB |
Output is correct |
12 |
Correct |
31 ms |
700 KB |
Output is correct |
13 |
Correct |
32 ms |
644 KB |
Output is correct |
14 |
Correct |
28 ms |
712 KB |
Output is correct |
15 |
Correct |
28 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
292 KB |
Output is correct |
4 |
Correct |
27 ms |
664 KB |
Output is correct |
5 |
Correct |
28 ms |
668 KB |
Output is correct |
6 |
Correct |
29 ms |
700 KB |
Output is correct |
7 |
Correct |
32 ms |
588 KB |
Output is correct |
8 |
Correct |
28 ms |
672 KB |
Output is correct |
9 |
Correct |
27 ms |
676 KB |
Output is correct |
10 |
Correct |
29 ms |
696 KB |
Output is correct |
11 |
Correct |
28 ms |
652 KB |
Output is correct |
12 |
Correct |
31 ms |
700 KB |
Output is correct |
13 |
Correct |
32 ms |
644 KB |
Output is correct |
14 |
Correct |
28 ms |
712 KB |
Output is correct |
15 |
Correct |
28 ms |
664 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
29 ms |
684 KB |
Output is correct |
18 |
Correct |
52 ms |
936 KB |
Output is correct |
19 |
Correct |
51 ms |
976 KB |
Output is correct |
20 |
Correct |
54 ms |
940 KB |
Output is correct |
21 |
Correct |
49 ms |
1020 KB |
Output is correct |
22 |
Correct |
49 ms |
928 KB |
Output is correct |
23 |
Correct |
50 ms |
948 KB |
Output is correct |
24 |
Correct |
50 ms |
980 KB |
Output is correct |
25 |
Correct |
52 ms |
976 KB |
Output is correct |
26 |
Correct |
56 ms |
956 KB |
Output is correct |
27 |
Correct |
62 ms |
940 KB |
Output is correct |
28 |
Correct |
53 ms |
992 KB |
Output is correct |
29 |
Correct |
49 ms |
944 KB |
Output is correct |
30 |
Correct |
51 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
296 KB |
Output is correct |
4 |
Correct |
52 ms |
968 KB |
Output is correct |
5 |
Runtime error |
4 ms |
1328 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |