说明

  • \(\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)(il-r的所有子区间中出现次数的异或幂) 的累异或,w(l,r)为(il-r的所有子区间的所有子区间中出现次数 的异或幂) 的累异或

其他理解

步骤

  1. 四组出前缀异或打表
  2. 按区间长度和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的更多相关文章

  1. 2019 ICPC南昌邀请赛网络赛比赛过程及题解

    解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M ...

  2. icpc 南昌邀请赛网络赛 Max answer

    就是求区间和与区间最小值的积的最大值 但是a[i]可能是负的 这就很坑 赛后看了好多dalao的博客 终于a了 这个问题我感觉可以分为两个步骤 第一步是对于每个元素 以它为最小值的最大区间是什么 第二 ...

  3. icpc 南昌邀请赛网络赛 Subsequence

    题目链接:https://nanti.jisuanke.com/t/38232 就是判断输入是不是子序列 没想到贡献了将近十几次罚时..........可以说是菜的真实了 用cin cout超时了 改 ...

  4. 南昌邀请赛网络赛 D.Match Stick Game(dp)

    南昌邀请赛网络赛 D.Match Stick Game 题目传送门 题目就会给你一个长度为n的字符串,其中\(1<n<100\).这个字符串是一个表达式,只有加减运算符,然后输入的每一个字 ...

  5. POJ-2796 & 2019南昌邀请赛网络赛 I. 区间最大min*sum

    http://poj.org/problem?id=2796 https://nanti.jisuanke.com/t/38228 背景 给定一个序列,对于任意区间,min表示区间中最小的数,sum表 ...

  6. 计蒜客 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 ...

  7. 2019南昌邀请赛网络赛:J distance on the tree

    1000ms 262144K   DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(N ...

  8. [2019南昌邀请赛网络赛D][dp]

    https://nanti.jisuanke.com/t/38223 Xiao Ming recently indulges in match stick game and he thinks he ...

  9. 计蒜客 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 ...

随机推荐

  1. 共享文件 Ubuntu下安装Samba与Windows

    Author:Xianghai Ding.Date:2019/01/08**************************************************************安装 ...

  2. 使用Eclipse来操作HDFS的文件

    一.常用类 1.Configuration Hadoop配置文件的管理类,该类的对象封装了客户端或者服务器的配置(配置集群时,所有的xml文件根节点都是configuration) 创建一个Confi ...

  3. mysql语句,插入id随机生成

    insert into 表名 VALUES(uuid(),…) 还有一个uuid_short(),只有数字 insert into 表名 VALUES(uuid_short(),…)

  4. 20175211 2018-2019-2 《Java程序设计》第五周学习总结

    目录 教材学习内容总结 第六章 接口与实现 教材学习中的问题和解决过程 代码调试中的问题和解决过程 代码托管 上周考试错题总结 学习进度条 参考资料 教材学习内容总结 第六章 接口与实现 6.1 接口 ...

  5. mysql执行update语句受影响行数是0

    mybatis连接mysql数据库,发现同一个update执行多次,返回的int值都是1. 我记得同样的update再次执行时 受影响行数是0. 后来发现,我之前一直用的SQLyog是这样子的. 原来 ...

  6. Go 初体验 - 并发与锁.1 - sync.Mutex 与 sync.RWMutex

    ==== Mutex为互斥锁,顾名思义,被Mutex锁住的代码同时只允许一个协程访问,其它协程进来就要排队 如何使用?看代码: 输出: 释义: 并发1000个协程同时更改m的元素,这样会有一部分更改成 ...

  7. zabbix监控实战<2>----zabbix-server的安装与部署

    第一章     zabbix-server的安装与部署 1.1  环境部署 eth0                               eth1 master      10.0.0.71  ...

  8. Linux交换Esc和Caps

    使用过 .xmodmap,重启后就失效,添加到rc.local也不管用,后来通过在xorg里配置成功. 更改xorg里的键盘配置,增加Option "XkbOptions" &qu ...

  9. JavaFX-Application

    JavaFX—Application 1.Application是JavaFX程序的入口,任何javafx应用程序程序都要继承该类并重写start()方法 public class TsetStage ...

  10. linux 扩展文件系统

    1. 创建新分区 [root@localhost ~]# fdisk -l Disk /dev/sda: bytes, sectors Units = sectors of * = bytes Sec ...