-
Notifications
You must be signed in to change notification settings - Fork 0
/
The_Brand_New_Function.cpp
46 lines (44 loc) · 1.18 KB
/
The_Brand_New_Function.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
#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<int> arr (N);
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
vector<vector<int> > nextIndex (N+1, vector<int> (20, -1));
for (int i = N-1; i >= 0; i--) {
for (int j = 0; j < 20; j++) {
if ((1 << j) & arr[i]) {
nextIndex[i][j] = i;
} else {
nextIndex[i][j] = nextIndex[i+1][j];
}
}
}
unordered_set<int> values;
for (int i = 0; i < N; i++) {
set<int> indexes;
for (int j = 0; j < 20; j++) {
if (nextIndex[i][j] != -1) {
indexes.insert(nextIndex[i][j]);
}
}
int value = arr[i];
values.insert(value);
//cout << value << " START " << endl;
for (auto const& index : indexes) {
value |= arr[index];
//cout << index << endl;
values.insert(value);
}
}
cout << values.size() << '\n';
return 0;
}