Niu Ke practice match 16 E evaluation

Topic description

Given n numbers a 1 , a 2 , ..., a n .
Define f(l, r) = a l | a l+1 | ... | a r .
Now enumerate (1 <= l <= r <= n) and ask how many different f values ​​there are.

Enter description:

An integer n in the first line represents the size of the array (1 <= n <= 100,000); 
the n integers in the second line satisfy 0 <= a
i
<= 1000,000。

Output description:

Output an integer indicating how many different f values ​​there are.
Example 1

enter

3
1 2 0

output

4
Example 2

enter

10
1 2 3 4 5 6 1 2 9 10

output

11 


Each time you enter a number xi, it is calculated on the basis of the previous one. How many are in front of 1-(i-1), 2-(i-1)....
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N = 2e6+10;
 4 set<int> st[2];
 5 bool vis[N];
 6 int x, n, last, ans;
 7 int main() {
 8     cin >> n;
 9     for(int i = 1; i <= n; i ++) {
10         cin >> x;
11         last = 1 - last;
12         st[last].clear();
13         set<int> :: iterator it = st[1-last].begin();
14         for(; it != st[1-last].end(); ++ it) {
15             int y = (*it)|x;
16             vis[y] = true;
17             st[last].insert(y);
18         }
19         st[last].insert(x);
20         vis[x] = true;
21     }
22     for(int i = 0; i < N; i ++) if(vis[i]) ans++;
23     cout << ans << endl;
24     return 0;
25 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325021379&siteId=291194637