题目入口
题意:t组测试数据,每组给你一个长度为n的序列a,能得到其任意子区间的OR值,求出所有OR值的种类数。
思路:比较好的一个思维题,用set存答案,再开两个set型的中间数组tmp,res。以当遍历到a[i]时,得到[1,i - 1],[2,i - 1],[3, i - 1]……的值,并分别与a[i]取或插入答案数组ans中。
代码实现:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#define int long long
#define lowbit(x) (x &(-x))
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {
{
1, 0}, {
-1, 0}, {
0, 1}, {
0, -1}};
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double EXP = 1e-8;
const ll MOD = 1e9 + 7;
const int N = 1e5 + 5;
int t, n;
int a[N];
signed main()
{
IOS;cin >> t;while(t --){
cin>> n;for(int i = 0; i < n; i ++)cin >> a[i];set<int> res, ans;for(int i = 0; i < n; i ++){
set<int> tmp;tmp.insert(a[i]);for(auto it : res)tmp.insert(it | a[i]);res = tmp;for(auto it : tmp)ans.insert(it);}cout << ans.size() << endl;}return 0;
}