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 ...
随机推荐
- 快递单号自动识别接口API-trackingmore
一.快递单号自动识别接口功能说明 (1)PC电脑端.移动APP或者自建网站集成物流查询功能时,只需要用户输入单号即可,不需要输入快递公司. (2)此接口可以配合Trackingmore的快递查询API ...
- redis集群及相关的使用
从redis 3.0之后版本支持redis-cluster集群,Redis-Cluster采用无中心结构,每个节点保存数据和整个集群状态,每个节点都和其他所有节点连接. 1.所有的redis节点彼此互 ...
- 【jdbc访问数据库获取执行sql转换json】
Talk is cheap.Show me your code. import java.sql.*; import java.util.HashMap; import java.util.Map; ...
- 学习MySQL过程中的随笔二
MySQL深入学习: 视图 使用视图的目的:多次使用同一张临时表(或者已经存在的表) 视图只是一个虚拟表,其本质为[根据SQL语句获取动态的数据集,并为其命名],用户只需使用别名即可获得实时的 ...
- 关闭 synactive guixt. 在sap gui的右上角一个标志里,将 active guixt 选项去掉即可。
关闭 synactive guixt. 在sap gui的右上角一个标志里,将 active guixt 选项去掉即可.
- encodeURIComponent 和 decodeURIComponent 对字符串url编码 用于url拼字符传值
- VisualVM监控远程服务器JVM
VisualVM是JDK自带的一款全能型性能监控和故障分析工具,包括对CPU使用.JVM堆内存消耗.线程.类加载的实时监控,内存dump文件分析,垃圾回收运行情况的可视化分析等,对故障排查和性能调优很 ...
- 安卓系统广播暴露设备信息-Android System Broadcasts Expose Device Information
Android device details are being exposed to running applications via Wi-Fi broadcasts in the mobile ...
- 以管理员身份运行 cmd 删除无权限删除的文件夹
rd 文件夹 PS:删除空文件夹 rd /s 文件夹 PS:删除文件夹,及所有子目录和文件 rd /s/q 文件夹 PS:强制删除文件夹,及所有子目录和文件,不需要提示
- Nginx配置选项
--prefix=path 定义一个目录,存放服务器上的文件 ,也就是nginx的安装目录.默认使用 /usr/local/nginx. --sbin-path=path 设置nginx的可执行 ...