#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
long long power[23];
long long pas[40005][3];
long long n;
void pow2calc(long long x){
power[1]=1;
for(long long i=2; i<=x; i++){
power[i]=power[i-1]*2;
}
}
pair<long long,long long> aa[2000002];
long long a1[2000002];
long long a[2000005];
int main(){
long long s;
pow2calc(22);
cin>>n;
cin>>s;
if(s==1){
long long k=0;
for(long long i=1; i<=n; i++){
cin>>a[i];
a1[i]=a[i];
aa[i].ff=a[i];
aa[i].ss=i;
}
sort(aa+1, aa+n+1);
long long lastsort=n;
while(lastsort!=1){
long long maxi=aa[lastsort].ss;
for(long long i=1; i<=lastsort-1; i++ ){
k++;
pas[k][1]=i;
pas[k][2]=i+1;
a1[i]=a1[i]^a1[i+1];
}
for(long long i=maxi+1; i<=lastsort; i++){
k++;
pas[k][1]=i;
pas[k][2]=i-1;
a1[i]=a1[i]^a1[i-1];
}
for(long long i=maxi-2; i>=1; i--){
k++;
pas[k][1]=i;
pas[k][2]=i+1;
a1[i]=a1[i]^a1[i+1];
}
for(long long i=1; i<=n; i++){
if(aa[i].ss>maxi){
aa[i].ss--;
}
}
lastsort--;
}
for(long long 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(long long i=1; i<=k; i++){
cout<<pas[i][1]<<" "<<pas[i][2]<<endl;
}
cout<<endl;
for(long long i=1; i<=n; i++){
// cout<<a1[i]<<" ";
}
}
if(s==2){
long long ax[n+1];
long long k=0;
for(long long i=1; i<=n; i++){
cin>>ax[i];
}
int last=n;
bool f=false;
for(long long i=22; i>=1; i--){
for(long long jj=1; jj<last; jj++){
if((power[i]&ax[jj])!=0){
// cout<<i<<" I"<<endl;
f=true;
// cout<<"xd "<<power[i]<<" "<<ax[jj+1]<<" "<<jj+1<<endl;
if((power[i]&ax[jj+1])==0){
k+=2;
// cout<<"y"<<jj<<" "<<jj+1<<endl<<jj+1<<" "<<jj<<endl;
ax[jj+1]^=ax[jj];
ax[jj]^=ax[jj+1];
pas[k-1][1]=jj+1;
pas[k-1][2]=jj;
pas[k][1]=jj;
pas[k][2]=jj+1;
}else{
// cout<<"n"<<jj<<" "<<jj+1<<endl;
k++;
ax[jj]^=ax[jj+1];
pas[k][1]=jj;
pas[k][2]=jj+1;
}
}
}
if(f==true){
last--;
}
// last--;
}
cout<<k<<endl;
for(long long i=1; i<=k; i++){
cout<<pas[i][1]<<" "<<pas[i][2]<<endl;
}
for(long long i=1; i<=n; i++){
// cout<<ax[i]<<" ";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
4 ms |
400 KB |
Output is correct |
4 |
Correct |
30 ms |
888 KB |
Output is correct |
5 |
Correct |
28 ms |
972 KB |
Output is correct |
6 |
Correct |
29 ms |
924 KB |
Output is correct |
7 |
Correct |
28 ms |
928 KB |
Output is correct |
8 |
Correct |
30 ms |
1108 KB |
Output is correct |
9 |
Correct |
29 ms |
972 KB |
Output is correct |
10 |
Correct |
32 ms |
912 KB |
Output is correct |
11 |
Correct |
29 ms |
948 KB |
Output is correct |
12 |
Correct |
30 ms |
932 KB |
Output is correct |
13 |
Correct |
29 ms |
912 KB |
Output is correct |
14 |
Correct |
30 ms |
904 KB |
Output is correct |
15 |
Correct |
30 ms |
964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
4 ms |
400 KB |
Output is correct |
4 |
Correct |
30 ms |
888 KB |
Output is correct |
5 |
Correct |
28 ms |
972 KB |
Output is correct |
6 |
Correct |
29 ms |
924 KB |
Output is correct |
7 |
Correct |
28 ms |
928 KB |
Output is correct |
8 |
Correct |
30 ms |
1108 KB |
Output is correct |
9 |
Correct |
29 ms |
972 KB |
Output is correct |
10 |
Correct |
32 ms |
912 KB |
Output is correct |
11 |
Correct |
29 ms |
948 KB |
Output is correct |
12 |
Correct |
30 ms |
932 KB |
Output is correct |
13 |
Correct |
29 ms |
912 KB |
Output is correct |
14 |
Correct |
30 ms |
904 KB |
Output is correct |
15 |
Correct |
30 ms |
964 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
30 ms |
972 KB |
Output is correct |
18 |
Correct |
53 ms |
1476 KB |
Output is correct |
19 |
Correct |
51 ms |
1532 KB |
Output is correct |
20 |
Correct |
51 ms |
1464 KB |
Output is correct |
21 |
Correct |
56 ms |
1464 KB |
Output is correct |
22 |
Correct |
52 ms |
1472 KB |
Output is correct |
23 |
Correct |
66 ms |
1492 KB |
Output is correct |
24 |
Correct |
51 ms |
1448 KB |
Output is correct |
25 |
Correct |
51 ms |
1484 KB |
Output is correct |
26 |
Correct |
60 ms |
1428 KB |
Output is correct |
27 |
Correct |
57 ms |
1380 KB |
Output is correct |
28 |
Correct |
55 ms |
1444 KB |
Output is correct |
29 |
Correct |
66 ms |
1368 KB |
Output is correct |
30 |
Correct |
51 ms |
1476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
9 ms |
484 KB |
Output is correct |
5 |
Correct |
39 ms |
1228 KB |
Output is correct |
6 |
Correct |
41 ms |
1168 KB |
Output is correct |
7 |
Correct |
39 ms |
1184 KB |
Output is correct |
8 |
Correct |
40 ms |
1160 KB |
Output is correct |
9 |
Correct |
41 ms |
1220 KB |
Output is correct |
10 |
Correct |
39 ms |
1220 KB |
Output is correct |
11 |
Correct |
39 ms |
1216 KB |
Output is correct |
12 |
Correct |
46 ms |
1228 KB |
Output is correct |
13 |
Correct |
43 ms |
1188 KB |
Output is correct |
14 |
Correct |
43 ms |
1232 KB |
Output is correct |
15 |
Correct |
54 ms |
1476 KB |
Output is correct |