标签:exp ase can alt blank href include 条件 style
由于位运算|在区间上是单调的,所以只需要算出每个从i开始的能到哪个j结束,使得(i,j)这个区间里面所有子区间都是满足条件的,即可。
1 #include <stdio.h> 2 #include <string.h> 3 typedef long long ll; 4 const int maxn = 1e5 + 5; 5 int n, m, a[maxn], b[31]; 6 inline int modify(int x, int v) { 7 int ret = 0; 8 for (int i = 0; i <= 30; ++i, x >>= 1) { 9 if (x & 1) 10 b[i] += v; 11 if (b[i]) 12 ret |= 1 << i; 13 } 14 return ret; 15 } 16 int main() { 17 int T; 18 scanf("%d", &T); 19 for (int Tc = 1; Tc <= T; ++Tc) { 20 scanf("%d%d", &n, &m); 21 for (int i = 0; i < n; ++i) 22 scanf("%d", &a[i]); 23 memset(b, 0, sizeof(b)); 24 int j = 0, tmp = 0; 25 ll ans = 0; 26 for (int i = 0; i < n; ++i) { 27 if (i) 28 tmp = modify(a[i - 1], -1); 29 while (j <= i || (j < n && (tmp | a[j]) < m)) 30 tmp = modify(a[j++], 1); 31 if (tmp < m) 32 ans += j - i; 33 } 34 printf("Case #%d: %lld\n", Tc, ans); 35 } 36 return 0; 37 }
标签:exp ase can alt blank href include 条件 style
原文地址:http://www.cnblogs.com/Apiec/p/6063077.html