UVALive - 7639 G - Extreme XOR Sum(思维)
题意
给出一个序列,相邻两两异或,生成一个新序列,再相邻两两异或,直到只剩下一个元素,问最后结果为多少。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(思维)的更多相关文章
- 【二项式定理】【DFS】UVALive - 7639 - Extreme XOR Sum
题意:一个序列,q次询问,每次问你某个指定区间内的EXtreme XOR值. 一个长度为l的区间的EXtreme XOR值被定义为,从左到右,将每相邻的两个数XOR起来,产生l-1个新的值,……如此循 ...
- uva live 7639 Extreme XOR Sum (暴力+二项式)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- HDU 4825 Xor Sum(经典01字典树+贪心)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Total ...
- 字典树-百度之星-Xor Sum
Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheu ...
- HDU 4825 Xor Sum 字典树+位运算
点击打开链接 Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) ...
- 2014百度之星第三题Xor Sum(字典树+异或运算)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Total ...
- Xor Sum 01字典树 hdu4825
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total S ...
- hdu 4825 Xor Sum (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...
- HDU--4825 Xor Sum (字典树)
题目链接:HDU--4825 Xor Sum mmp sb字典树因为数组开的不够大一直wa 不是报的 re!!! 找了一下午bug 草 把每个数转化成二进制存字典树里面 然后尽量取与x这个位置上不相同 ...
随机推荐
- PAT 1039 到底买不买
https://pintia.cn/problem-sets/994805260223102976/problems/994805283241443328 小红想买些珠子做一串自己喜欢的珠串.卖珠子的 ...
- centos7 服务操作命令
systemctl list-unit-files --type service --all 操作防火墙: https://www.jianshu.com/p/411274f96492 操作VNC: ...
- Under the same directory(folder) copy or rename with the different extension name
@echo offsetlocal EnableDelayedExpansionfor /f "delims=" %%i in ('dir *.vm /q/s/b') do ( c ...
- 用IntelliJ IDEA编译,编译之后提示 无效的标记: -release
软件版本:ideaIU-2016.3.2 JDK:jdk-9.0.4_windows-x64_bin 开始的时候建立一个maven项目,发现编译的时候提示[无效的标记: -release],以为是项目 ...
- ASP.NET MVC缓存使用
局部缓存(Partial Page) 1.新建局部缓存控制器: public class PartialCacheController : Controller { // GET: /PartialC ...
- PHP 4种输出的方式
<?php //测试用的数组 $info = array('11'=>'aaa', '22'=>'bbb', '33'=>'ccc'); //第一种,将整个数组作为一个对象输出 ...
- python matplotlib绘图
import numpy as np import matplotlib.pyplot as plt from scipy.constants.constants import alpha from ...
- SQL ROUND函数的使用
SQL ROUND函数的使用 SQL ROUND函数是对数据进行制定精度的取值. 第一个参数是取值的数据,第二个参数是精度,第三个参数是数据取值模式(四舍五入还是截断),其中第三个参数是可选参数, ...
- Bootstrap排版——HTML元素的样式重定义
前面的话 Bootstrap对默认的HTML元素进行了CSS样式定义,使得各种基本结构套用出来的HTML页面更加美观.本文将详细介绍Bootstrap中排版相关的内容 标题 [h] HTML 中的所有 ...
- i3 窗口管理器使 Linux 更美好
导读 Linux(和一般的开源软件)最美好的一点是自由 —— 可以在不同的替代方案中进行选择以满足我们的需求. 我使用 Linux 已经很长时间了,但我从来没有对可选用的桌面环境完全满意过.直到去年, ...