奉献一个线段树nlogn的做法= =
网上各种暴力太不靠谱了= =
那个30*n的感觉还是不够好。。。。
按照暴力的思路 我们要找每一个i最右能到的位置ed
然后我们可以一个个的更新 利用x|0 = x
初始化每个点都是0
每一次到i这个位置的时候把i-1更新为0,然后一直往右添加点ed直到异或>=m为止
到下一个点的时候接着这个ed往右更新就行了
//#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <stack>
#include <queue>
using namespace std;
template<class T> inline T sqr(T x) { return x * x; }
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef pair<LL, LL> PLL;
typedef pair<LL, int> PLI;
typedef pair<LD, LD> PDD;
#define MP make_pair
#define PB push_back
#define sz(x) ((int)(x).size())
#define clr(ar,val) memset(ar, val, sizeof(ar))
#define istr stringstream
#define FOR(i,n) for(int i=0;i<(n);++i)
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const LL LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define MAXN 100005
int a[MAXN];
struct Node{
int v;
} nd[MAXN<<2];
class SegTree{
public:
int v,pos;
SegTree(int n){
build(1,n,1);
}
void build(int l,int r,int rt){
nd[rt].v = 0;
if(l!=r){
int mid = (l+r)>>1;
build(lson);
build(rson);
}
}
void update(int l,int r,int rt){
if(l==r){
nd[rt].v = v;
}
else{
int mid = (l+r)>>1;
if(pos<=mid) update(lson);
else update(rson);
nd[rt].v = (nd[rt<<1].v|nd[rt<<1|1].v);
}
}
};
int main(void){
#ifndef ONLINE_JUDGE
freopen("/home/xing89qs/桌面/data.in","r",stdin);
#endif
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d %d",&n,&m);
for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
LL ans = 0;
SegTree seg(n);
int ed = 0;
for(int i = 1;i<=n;i++){
if(i>1){
seg.pos = i-1;
seg.v = 0;
seg.update(1,n,1);
}
if(ed<i-1) ed = i-1;
while(ed<n&&(nd[1].v|a[ed+1])<m){
seg.pos = ed+1;
seg.v = a[ed+1];
seg.update(1,n,1);
ed++;
}
ans+=ed-i+1;
}
static int ca = 1;
printf("Case #%d: %I64d\n",ca++,ans);
}
}