Subarrays OR Gym - 102152K(思维)

时间:2020-04-15
本文章向大家介绍Subarrays OR Gym - 102152K(思维),主要包括Subarrays OR Gym - 102152K(思维)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Output

For each test case, print a single line containing the number of unique subarrays OR values among the subarray OR values of all subarrays in the given array.

Example

Input
2
3
1 2 3
3
2 4 8
Output
3
6

Note


题意:对任意一个L,R操作一共有多少个不同的异或值。

思路:假设现在想要求解区间[1,i][1,i]内的答案,那么需要先处理出[1,i1],[2,i1],[3,i1]......[i1,i1]。然后将这些答案暴力与ai|

代码:

#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
//#include <unordered_map>
#define Fbo friend bool operator < (node a, node b)
#define mem(a, b) memset(a, b, sizeof(a))
#define FOR(a, b, c) for (int a = b; a <= c; a++)
#define RFOR(a, b, c) for (int a = b; a >= c; a--)
#define off ios::sync_with_stdio(0)
#define sc(a) scanf("%d",&a)
#define pr(a) printf("%d\n",a);
#define SC(n,m) scanf("%d%d",&n,&m)
bool check1(int a) { return (a & (a - 1)) == 0 ? true : false; }

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int INF = 0x3f3f3f3f;//1e10
const int mod = 1e9 + 7;
const int Maxn = 1e5 + 5;
const int M = Maxn * 20;
const double pi = acos(-1.0);
const double eps = 1e-8;

int a[Maxn];

int main() {
    int t;
    sc(t);
    while (t--) {
        int n;
        sc(n);
        FOR (i, 1, n)  sc(a[i]);
        set<int>s, st, ans;
        FOR(i, 1, n) {
            s.clear();
            s.insert(a[i]);
            for (auto x : st) {
                s.insert(a[i]|x);
                //printf("%d | %d = %d\n", a[i], x, a[i] | x);
            }
            st = s;
            for (auto x : st) {
                //cout << "答案" << x << endl;
                ans.insert(x);
            }
        }
        cout << ans.size() << endl;
    }
}

原文地址:https://www.cnblogs.com/AlexLINS/p/12707148.html