-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnd_Or_Union.cpp
More file actions
199 lines (168 loc) · 4.12 KB
/
And_Or_Union.cpp
File metadata and controls
199 lines (168 loc) · 4.12 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//And_Or_Union
//https://www.codechef.com/START21B/submit/ANDORUNI
#include <bits/stdc++.h>
//#include<vector>
//#include<queue>
//#include<stack>
//#include<set>
//#include<map>
//#include<unordered_set>
//#include<unordered_map>
//#include<deque>
//#include<utility>
//#include<priority_queue>
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include<stdlib.h>
//#include<math.h>
//#include<time.h>
//#include<climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define MAX INT_MAX
#define MIN INT_MIN
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
// loop
#define fo(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define foe(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define foge(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define fosq(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define foc(a, b, c) for (char(a) = (b); (a) < (c); ++(a))
#define foce(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define foat(a, b) for (auto &(a) : (b))
#define foall(a, b) for (auto(a) : (b))
#define range(i, n) fo(i, 0, n)
// util
#define sqr(x) ((x) * (x))
#define minele(a) *min_element(all(a))
#define maxele(a) *max_element(all(a))
#define sum(a) accumulate(all(a), 0)
void fastscan(int &number)
{
//variable to indicate sign of input number
bool negative = false;
register int c;
number = 0;
// extract current character from buffer
c = getchar();
if (c == '-')
{
// number is negative
negative = true;
// extract the next character from the buffer
c = getchar();
}
// Keep on extracting characters if they are integers
// i.e ASCII Value lies from '0'(48) to '9' (57)
for (; (c > 47 && c < 58); c = getchar())
number = number * 10 + c - 48;
// if scanned input has a negative sign, negate the
// value of the input number
if (negative)
number *= -1;
}
void getPairsMerge(int arr[], int l, int r, int mid, vector<pair<int, int>> &p)
{
int b[l + r + 1], i = l, k = l, j = mid + 1;
while (i <= mid && j <= r)
{
if (arr[i] > arr[j])
{
b[k] = arr[j];
p.push_back({arr[i], arr[j]});
p.push_back({arr[j], arr[i]});
p.push_back({arr[j], arr[j]});
k++;
j++;
}
else
{
p.push_back({arr[i], arr[j]});
p.push_back({arr[j], arr[i]});
p.push_back({arr[i], arr[i]});
b[k] = arr[i];
i++;
k++;
}
}
while (i <= mid)
{
b[k] = arr[i];
p.push_back({arr[i], arr[i]});
i++;
k++;
}
while (j <= r)
{
b[k] = arr[j];
p.push_back({arr[j], arr[j]});
j++;
k++;
}
for (int x = l; x <= r; x++)
{
arr[x] = b[x];
}
}
void getAllPairs(int arr[], int l, int r, vector<pair<int, int>> &p)
{
if (l < r)
{
int mid = (l + r) / 2;
getAllPairs(arr, l, mid, p);
getAllPairs(arr, mid + 1, r, p);
getPairsMerge(arr, l, r, mid, p);
}
}
//driver code
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int Test;
cin >> Test;
while (Test--)
{
//solution start
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
vector<int> count(31);
for(int bit=30; bit>=0; bit--) {
for(int i=0; i<n; i++) {
if((1 << bit) & a[i]) {
count[bit]++;
}
}
}
int res = 0;
for(int bit=30; bit>=0; bit--) {
if(count[bit] > 1) {
res += (1 << bit);
}
}
cout<<res<<"\n";
//solution end
}
return 0;
}