-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode_898.cpp
More file actions
54 lines (53 loc) · 1.49 KB
/
Copy pathleetcode_898.cpp
File metadata and controls
54 lines (53 loc) · 1.49 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
/*
Bitwise ORs of Subarrays solution
author : chogahui05 (kyungwan cho)
*/
class Solution {
public:
int subarrayBitwiseORs(vector<int>& A) {
vector <int> P; P.clear();
vector <int> C; C.clear();
vector <int> R; R.clear();
vector <int> T; T.clear();
for(int i=0;i<(int)A.size();i++)
{
int te = A[i];
C.push_back(te);
for(int j=0;j<(int)P.size();j++)
C.push_back(te|P[j]);
C.erase(unique(C.begin(),C.end()),C.end()); P.clear();
for(int j=0;j<(int)C.size();j++)
{
P.push_back(C[j]); R.push_back(C[j]);
}
C.clear();
}
radix_sort(R,T);
R.erase(unique(R.begin(),R.end()),R.end());
return (int)R.size();
}
void radix_sort(vector <int> &R,vector <int> &T)
{
int co[65536] = {0}; T.resize(R.size());
for(int i=0;i<R.size();i++)
co[R[i]&65535]++;
for(int i=1;i<65536;i++)
co[i] += co[i-1];
for(int i=0;i<R.size();i++)
{
int kei = (R[i]&65535); co[kei]--;
T[co[kei]] = R[i];
}
for(int i=0;i<65536;i++)
co[i] = 0;
for(int i=0;i<T.size();i++)
co[T[i]>>16]++;
for(int i=1;i<65536;i++)
co[i] += co[i-1];
for(int i=0;i<T.size();i++)
{
int kei = (T[i]>>16); co[kei]--;
R[co[kei]] = T[i];
}
}
};