题目链接

题意;给个数组,每次询问一个区间你可以挑任意个数的数字异或和 然后在或上k的最大值

题解:线性基不知道的先看这个,一个线性基可以log的求最大值把对应去区间的线性基求出来然后用线段树维护线性基

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define maxn 100009
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
int read()
{
    char ch=' ';
    ;
    ')
        ch=getchar();
    ')
    {
        ans=ans*+ch-';
        ch=getchar();
    }
    return ans;
}
struct ac{
   ];
   void init(){
      memset(a,,sizeof(a));
   }
   bool add(int x){
       ;j>=;j--){
          <<j)){
             if(!a[j]){
                a[j]=x;
                break;
             }
             x^=a[j];
          }
       }
       ;
   }
   int query(){
      ;
      ;j>=;j--){
         if((x^a[j])>x){
            x^=a[j];
         }
      }
      return x;
   }
   ac merge_LB(ac x){
        ac ret;
        ;i<=;i++){
            ret.a[i]=a[i];
        }
        ;i<=;i++){
            ret.add(x.a[i]);
        }
        return ret;
   }
}tre[maxn*];
int b[maxn];
void build(int l,int r,int in){
  tre[in].init();
  if(l==r){
    tre[in].add(b[l]);
    return ;
  }
  ;
  build(l,mid,);
  build(mid+,r,+);
  tre[].merge_LB(tre[+]);
}
ac query(int l,int r,int x,int y,int in){
   if(l==x&&r==y){
        return tre[in];
    }
    ;
    //ac ret;ret.init();
    ));
    ,y,+));
    ).merge_LB(query(mid+,r,mid+,y,+));
}
int main(){
   int t;
   cin>>t;
   while(t--){
      int n,m,k;
     //scanf("%d%d%d",&n,&m,&k);
      n=read();m=read();k=read();
      k=~k;
      ;j<=n;j++){
         scanf("%d",&b[j]);
         b[j]&=k;
      }
      k=~k;
      build(,n,);
      ;j<m;j++){
          int l,r;
          //scanf("%d%d",&l,&r);
          l=read();r=read();
          ac ans=query(l,r,,n,);
          int an=ans.query();
          an|=k;
          printf("%d\n",an);
      }
   }
}

ACM-ICPC 2017 Asia Xi'an A XOR (线性基+线段树思想)的更多相关文章

  1. ACM-ICPC 2017 西安赛区现场赛 A. XOR(线性基+线段树)

    题目链接:https://nanti.jisuanke.com/t/20749 参考题解:https://blog.csdn.net/Lee_w_j__/article/details/8266418 ...

  2. 计蒜客 A1607 UVALive 8512 [ACM-ICPC 2017 Asia Xi'an]XOR

    ICPC官网题面假的,要下载PDF,点了提交还找不到结果在哪看(我没找到),用VJ交还直接return 0;也能AC 计蒜客题面 这个好 Time limit 3000 ms OS Linux 题目来 ...

  3. ACM-ICPC 2017 Asia Xi'an

    ACM-ICPC 2017 Asia Xi'an Solved A B C D E F G H I J K 7/11 O O Ø O O ? O O O for passing during the ...

  4. ACM ICPC 2017 Warmup Contest 9 I

    I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...

  5. ACM ICPC 2017 Warmup Contest 9 L

    L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...

  6. luogu P2574 XOR的艺术 (线段树)

    luogu P2574 XOR的艺术 (线段树) 算是比较简单的线段树. 当区间修改时.\(1 xor 1 = 0,0 xor 1 = 1\)所以就是区间元素个数减去以前的\(1\)的个数就是现在\( ...

  7. HDU 5475(2015 ICPC上海站网络赛)--- An easy problem(线段树点修改)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5475 Problem Description One day, a useless calculato ...

  8. codeforces 22E XOR on Segment 线段树

    题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 seconds ...

  9. Xor && 线性基练习

    #include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...

随机推荐

  1. C#复习笔记(4)--C#3:革新写代码的方式(用智能的编译器来防错)

    用智能的编译器来防错 本章的主要内容: 自动实现的属性:编写由字段直接支持的简单属性, 不再显得臃肿不堪: 隐式类型的局部变量:根据初始值推断类型,简化局部变量的声明: 对象和集合初始化程序:用一个表 ...

  2. [转帖]Centos7 yum安装Chrome浏览器

    Centos7 yum安装Chrome浏览器 https://www.cnblogs.com/ianduin/p/8727333.html以及https://blog.csdn.net/libaine ...

  3. cmake : undefined reference to dlopen, dlclose, dlsym and dlerror

    链接出了问题 添加头文件 #include <dlfcn.h> 添加库 target_link_libraries(PROJECT_NAME ${CMAKE_DL_LIBS})

  4. spring boot中常用的配置文件的重写

    @Configuration public class viewConfigSolver extends WebMvcConfigurerAdapter { /* spring boot 已经自动配置 ...

  5. Centos6.8 安装nginx

    1.安装相关依赖 (1)yum install gcc 备注:可以通过gcc -v 查看版本信息,来确定是否安装过. (2)yum install pcre-devel (3)yum install ...

  6. kprobe原理解析

    参考  http://www.cnblogs.com/honpey/p/4575928.html kprobe是linux内核的一个重要特性,是一个轻量级的内核调试工具,同时它又是其他一些更高级的内核 ...

  7. 老男孩python学习自修第二十三天【多线程】

    1. 线程的创建与运行 #!/usr/bin/env python # _*_ coding:UTF-8 _*_ from threading import Thread def foo(param1 ...

  8. 转载 -- jquery easyui datagrid 动态表头 + 嵌套对象属性展示

    代码功能: 1.datagrid 的表头由后台生成,可以配置在数据库 2.datagrid 的列绑定数据 支撑嵌套对象 $(function() { var columns = new Array() ...

  9. MySQL 索引长度和区分度

    首先  索引长度和区分度是相互矛盾的, 索引长度太短,那么区分度就很低,吧索引长度加长,区分度就高,但是索引也是要占内存的,所以我们需要找到一个平衡点: 那么这个平衡点怎么来定? 比如用户表有个字段 ...

  10. Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code

    Editor’s Note: The following is a guest post from Mustafa Mahmutović, a Microsoft Student Partner wh ...