codeforces 243A

题目:http://codeforces.com/problemset/problem/243/A


其实就是个利用位运算的知识简单的暴力。。但是比赛的时候我用的一种贪心策略超时了= =!!。

找区间【l,r】的所有位运算可能产生的结果,暴力的方法。直接两重for循环。但是题目n的常数为10^5,肯定会超时。

所以要换一种思路。要找 v[r]  与前面[l,r-1]的所产生的|结果,如果v[r]|v[r-1]==v[r-1]|v[r-2]..那么后面的循环就不用做了。因为产生的答案前面已经做过了。


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <stack>
using namespace std;
typedef long long LL;
#define EPS 10e-9
#define INF 0x3f3f3f3f
#define REP(i,n) for(int i=0; i<(n); i++)
bool used[1048586];
int v[100100];
int main(){
    int n;
    scanf("%d",&n);
    REP(i,n)  scanf("%d",&v[i]);
    REP(i,n){
        int x=v[i];
        int y=0;
        int j=i-1;
        used[x]=true;
        while(1){
            if(j<0) break;
            x=x|v[j];
            y=y|v[j];
            if(x==y) break;
            used[x]=true;
            j--;
        }
    }
    int res=0;
    REP(i,1048586){
        if(used[i]) res++;
     }
     printf("%d\n",res);
   return 0;
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值