A Bit Fun

The idea is: when the function of the resulting sum is greater than m, does not have to continue with the subsequent determination, or because the operator will only make a few large!
AC Code (249ms):

/*代码没注释,回看两行泪*/
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <assert.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int t;
int a[100010];

int main(){
	cin>>t;
	int n,m;int cnt=1;
	while(t--){
		ll res=0;
		
        cin>>n>>m; 
        for(int i=0;i<n;i++){
        	scanf("%d",&a[i]);
		}
		for(int i=0;i<n;i++){
			int j=i;
			ll ans=a[j];
			while(ans<m&&j<n){
				ans |= a[++j];
				res++;
			} 
		}
		printf("Case #%d: %d\n",cnt,res);
		cnt++;
	} 
	return 0;
}

Guess you like

Origin blog.csdn.net/Csdn_jey/article/details/92013057
Bit
BIT