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
2 3 1 2 3 3 2 4 8
3 6
Note
题意:对任意一个L,R操作一共有多少个不同的异或值。
思路:假设现在想要求解区间[1,i][1,i]内的答案,那么需要先处理出[1,i−1],[2,i−1],[3,i−1]......[i−1,i−1]。然后将这些答案暴力与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; } }
Subarrays OR Gym - 102152K(思维)
原文:https://www.cnblogs.com/AlexLINS/p/12707148.html