2019 ICPC南昌邀请赛 网络赛 K. MORE XOR
说明
- \(\oplus x\)为累异或
- $ x^{\oplus(a)}$为异或幂
题意&解法
$ f(l,r)=\oplus_{i=l}^{r} a[i]\(
\) g(l,r)=\oplus_{i=l}{r}a[i]{\oplus((i-l+1)*(r-i+1))}$

\(\begin{alignat}{} w(l,r)&=\oplus_{i=l}^{r}a[i]^{\oplus(\frac{(i-l+1)*(i-l+2)}2*\frac{(r-i+1)*(i-l+2)}2)}&\\&=\begin{cases}a[l]\oplus a[l+4]\oplus \cdots\oplus a[r]&len\text{%}4=1\\a[l]\oplus a[l+1]\oplus s[l+4]\oplus a[l+5]\oplus\cdots\oplus a[r-1]\oplus a[r]&len\text{%}4=2\\a[l+1]\oplus a[l+5]\oplus\cdots\oplus a[r-1]&len\text{%}4=3\\0&len\text{%}4=4\end{cases}&(len=r-l+1)\end{alignat}\)
即f(l,r)为异或和,g(l,r)为(i在l-r的所有子区间中出现次数的异或幂) 的累异或,w(l,r)为(i在l-r的所有子区间的所有子区间中出现次数 的异或幂) 的累异或
步骤
- 四组出前缀异或打表
- 按区间长度和
l所在位置分组计算
代码
#include<cstdio>
using namespace std;
const int maxn=100005;
int t,n,q,a[maxn],sum[maxn];
inline int Sum(int l,int r)
{
if(l-4>=0)
return sum[r]^sum[l-4];
else
return sum[r];
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]),
i-4>=0?sum[i]=sum[i-4]^a[i]:sum[i]=a[i];
scanf("%d",&q);
for(int i=0,l,r;i<q;i++)
{
int ans;
scanf("%d%d",&l,&r);l--;r--;
if((r-l+1)%4==1){//l...l+4...l+8...r
ans=Sum(l,r);
}
else if((r-l+1)%4==2){//l.l+1...l+4.l+5...r-1.r
ans=Sum(l,r-1)^Sum(l+1,r);
}
else if((r-l+1)%4==3){//l+1...l+5...r-1
ans=Sum(l+1,r-1);
}
else
ans=0;
printf("%d\n",ans);
}
}
return 0;
}
2019 ICPC南昌邀请赛 网络赛 K. MORE XOR的更多相关文章
- 2019 ICPC南昌邀请赛网络赛比赛过程及题解
解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M ...
- icpc 南昌邀请赛网络赛 Max answer
就是求区间和与区间最小值的积的最大值 但是a[i]可能是负的 这就很坑 赛后看了好多dalao的博客 终于a了 这个问题我感觉可以分为两个步骤 第一步是对于每个元素 以它为最小值的最大区间是什么 第二 ...
- icpc 南昌邀请赛网络赛 Subsequence
题目链接:https://nanti.jisuanke.com/t/38232 就是判断输入是不是子序列 没想到贡献了将近十几次罚时..........可以说是菜的真实了 用cin cout超时了 改 ...
- 南昌邀请赛网络赛 D.Match Stick Game(dp)
南昌邀请赛网络赛 D.Match Stick Game 题目传送门 题目就会给你一个长度为n的字符串,其中\(1<n<100\).这个字符串是一个表达式,只有加减运算符,然后输入的每一个字 ...
- POJ-2796 & 2019南昌邀请赛网络赛 I. 区间最大min*sum
http://poj.org/problem?id=2796 https://nanti.jisuanke.com/t/38228 背景 给定一个序列,对于任意区间,min表示区间中最小的数,sum表 ...
- 计蒜客 38229.Distance on the tree-1.树链剖分(边权)+可持久化线段树(区间小于等于k的数的个数)+离散化+离线处理 or 2.树上第k大(主席树)+二分+离散化+在线查询 (The Preliminary Contest for ICPC China Nanchang National Invitational 南昌邀请赛网络赛)
Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NO ...
- 2019南昌邀请赛网络赛:J distance on the tree
1000ms 262144K DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(N ...
- [2019南昌邀请赛网络赛D][dp]
https://nanti.jisuanke.com/t/38223 Xiao Ming recently indulges in match stick game and he thinks he ...
- 计蒜客 38228. Max answer-线段树维护单调栈(The Preliminary Contest for ICPC China Nanchang National Invitational I. Max answer 南昌邀请赛网络赛) 2019ICPC南昌邀请赛网络赛
Max answer Alice has a magic array. She suggests that the value of a interval is equal to the sum of ...
随机推荐
- Log print(Android)
Log.v("MyTag", "This is Verbose."); Log.d("MyTag", "This i ...
- Vue框架创建项目常遇到问题
利用npm安装cnpm时出现的错误 npm WARN deprecated socks@1.1.10: If using 2.x branch, please upgrade to at least ...
- 框架的一些bug问题记录
关于java后台生成的mis表,在添加的add页面和edit页面中无法显示,去控制台里面查看.会有些错误的信息,是由于,你的那些html的标签不正常.导致无法显示. 里面有一个高级搜索,可以对这个选择 ...
- 在eclipse中的交叉编译
1.硬件是Arm 9的板子,运行的系统是Ubuntu 12.05 2.电脑虚拟机上安装的系统是Ubuntu 10.04,程序的开发都是在虚拟机上完成,开发IDE是eclipse 3.eclipse 默 ...
- nginx+fastCGI
首先贴些遇到的问题,之后再整理 1.yum -y install pcre zlib OpenSSL openssl-devel pcre-devel 2. nginx: [emerg] " ...
- mysql杯观锁与乐观锁
悲观锁与乐观锁是两种常见的资源并发锁设计思路,也是并发编程中一个非常基础的概念.本文将对这两种常见的锁机制在数据库数据上的实现进行比较系统的介绍. 悲观锁(Pessimistic Lock) 悲观锁的 ...
- vue的计算属性computed和监听器watch
<template> <div> this is A.vue <br> <!--计算属性--> <label for="msg" ...
- ajax 防止重复提交
参考链接:http://www.hollischuang.com/archives/931 http://blog.csdn.net/everything1209/article/details/52 ...
- Go语言文件操作
打开和关闭文件 os.Open()函数能够打开一个文件,返回一个*File和一个err. file.close()方法能够关闭文件. //打开和关闭文件 func main() { file,err ...
- python class继承
https://blog.csdn.net/brucewong0516/article/details/79121179 类继承: class SubClassName(parentClass,[,p ...