-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitwise Blend.cpp
176 lines (157 loc) · 3.16 KB
/
Bitwise Blend.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
long long be1[200002];
long long be2[200002];
long long Be1=0;
long long Be2=0;
//first function
void function1(long long x,long long y){
be1[Be1]=x;
Be1++;
be1[Be1]=y;
Be1++;
}
//second function
void function2(long long x,long long y){
be2[Be2]=x;
Be2++;
be2[Be2]=y;
Be2++;
}
//main function
int main()
{
long long t;
cin >> t;
while(t--){
Be1=0;
Be2=0;
long long count_1 = 0;
long long count_2 = 0;
long long n;
cin >> n;
long long a[n];
long long A[n];
long long Y1=0,Y=2;
long long y1=0,y=0;
long long odd_check =0;
for(long long i=0; i<n ;i++){
cin>>a[i];
A[i]=a[i];
}
if(a[0]%2==0)
{
if(a[1]%2==0){
for(long long i=2;i<n;i++){
if(a[i]%2==1){
Y1=a[i];
y1=i;
odd_check = 1;
a[1] = a[1]^Y1;
count_1++;
function1(1,y1);
break;
}
}
}
else{
Y1=a[1];
y1=1;
odd_check = 1;
}
Y=a[1];
y=1;
for(long long i =2;i<n;i++){
if(a[i]%2==1){
a[i]=a[i]^Y;
count_1++;
function1(i,y);
}
i++;
if(i<n){
if(a[i]%2==0){
a[i]=a[i]^Y;
count_1++;
function1(i,y);
}
}
}
A[0]=A[0]^Y1;
count_2++;
function2(0,y1);
Y=A[0];
y=0;
for(long long i=1;i<n;i++){
if(A[i]%2==1){
A[i]=A[i]^Y;
count_2++;
function2(i,y);
}
i++;
if(i<n){
if(A[i]%2==0){
A[i]=A[i]^Y;
count_2++;
function2(i,y);
}
}
}
}
else{
odd_check = 1;
Y=A[0];
y=0;
for(long long i=1;i<n;i++){
if(a[i]%2==1){
a[i]=a[i]^Y;
count_1++;
function1(i,y);
}
i++;
if(a[i]%2==0 && i<n){
a[i]=a[i]^Y;
count_1++;
function1(i,y);
}
}
Y = A[0];
y=0;
for(long long i=1;i<n;i++){
if(A[i]%2==0){
A[i]=A[i]^Y;
count_2++;
function2(i,y);
}
i++;
if(A[i]%2==1 && i<n){
A[i]=A[i]^Y;
count_2++;
function2(i,y);
}
}
A[0]=A[0]^A[1];
count_2++;
function2(0,1);
}
if(odd_check==0){
cout<<"-1"<<endl;
}
else if(count_1>count_2){
long long j;
cout<<count_2<<endl;
for(long long i=0;i<count_2;i++){
j=i*2;
cout<<be2[j]+1<<" "<<be2[j+1]+1<<endl;
}
}
else{
int j;
cout<<count_1<<endl;
for(long long i=0;i<count_1;i++){
j=i*2;
cout<<be1[j]+1<<" "<<be1[j+1]+1<<endl;
} }
}
return 0;
}