hdu 4737

奉献一个线段树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);
    }
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值