题目链接

题意

给出一个序列,相邻两两异或,生成一个新序列,再相邻两两异或,直到只剩下一个元素,问最后结果为多少。m个查询,每次都有一个待查询区间。

分析

既然有多组查询,n只是1e4,那么可以考虑预处理。
预处理出每种长度的区间最后剩下的元素位置。然后就O(1)查询了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
const int maxn=1e4+;
const int inf=0x3f3f3f3f;
const int mod=1e9+;
int a[maxn],num[maxn];
vector<int> v[maxn];
void init(){
for(int i=;i<maxn;i++){
num[]=num[i]=;
for(int j=i-;j>;j--) num[j]^=num[j-];
for(int j=;j<=i;j++)
if(num[j]) v[i].push_back(j);
}
} int main(){
init();
int t;
scanf("%d",&t);
for(int k=;k<=t;k++){
int n;
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&a[i]);
int q;
scanf("%d",&q);
printf("Case %d:\n",k);
while(q--){
int l,r;
scanf("%d%d",&l,&r);
int ans=;
for(int i=;i<v[r-l+].size();i++) ans^=a[l+v[r-l+][i]-];
printf("%d\n",ans);
}
}
return ;
}

UVALive - 7639 G - Extreme XOR Sum(思维)的更多相关文章

  1. 【二项式定理】【DFS】UVALive - 7639 - Extreme XOR Sum

    题意:一个序列,q次询问,每次问你某个指定区间内的EXtreme XOR值. 一个长度为l的区间的EXtreme XOR值被定义为,从左到右,将每相邻的两个数XOR起来,产生l-1个新的值,……如此循 ...

  2. uva live 7639 Extreme XOR Sum (暴力+二项式)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  3. HDU 4825 Xor Sum(经典01字典树+贪心)

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total ...

  4. 字典树-百度之星-Xor Sum

    Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheu ...

  5. HDU 4825 Xor Sum 字典树+位运算

    点击打开链接 Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) ...

  6. 2014百度之星第三题Xor Sum(字典树+异或运算)

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total ...

  7. Xor Sum 01字典树 hdu4825

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total S ...

  8. hdu 4825 Xor Sum (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...

  9. HDU--4825 Xor Sum (字典树)

    题目链接:HDU--4825 Xor Sum mmp sb字典树因为数组开的不够大一直wa 不是报的 re!!! 找了一下午bug 草 把每个数转化成二进制存字典树里面 然后尽量取与x这个位置上不相同 ...

随机推荐

  1. Linux: HowTo See Directory Tree Structure

    https://www.cyberciti.biz/faq/linux-show-directory-structure-command-line/ Linux: HowTo See Director ...

  2. python pip包安装以及几个包的简单用法

    1. centos74 安装完之后默认有python2.7.5 但是没有pip需要自己安装: copy from https://www.cnblogs.com/rain124/p/6196053.h ...

  3. React 表单refs

    <!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...

  4. SAP PA认证

    ----------------------------------------------------------------转帖---------------------------------- ...

  5. NodeJS中的require和import

    ES6标准发布后,module成为标准,标准的使用是以export指令导出接口,以import引入模块,但是在我们一贯的node模块中,我们采用的是CommonJS规范,使用require引入模块,使 ...

  6. python中Switch/Case实现

    学习Python过程中,发现没有switch-case,过去写C习惯用Switch/Case语句,官方文档说通过if-elif实现.所以不妨自己来实现Switch/Case功能. 方法一 通过字典实现 ...

  7. 关于封装了gevent的request grequest库的使用与讨论

    最近迷上了gevent所以研究很多gevent相关的东西. 但是我现在不想写相关gevent和greenlet的东西.因为这一块内容实在太多太大太杂,我自己也还没有完全弄明白,所以等我完全搞清楚测试也 ...

  8. Java微信二次开发(八)

    高级接口,先做了两个(获取用户信息和获取关注者列表) 第一步:找到包com.wtz.vo,新建类UserInfo.java package com.wtz.vo; /** * @author wang ...

  9. c-lodop云打印实现手机打印 JS语句打印

    Lodop和c-lodop目前只能安装到windows操作系统上,但是其他操作系统可通过向C-Lodop安装的电脑发送打印任务,实现手机广域网或局域网打印,打印语句也是简单的JS语句,可以轻松实现云打 ...

  10. python 模块之-hashlib

    python 模块hashlib import hashlib m=hashlib.md5()         # 生成MD5加密对象 m.update('jiami-string'.encode(' ...