设\(xorx[l][r]\)表示题目中\(f(l,r)\)的值,则可以得出

\[xorx[i][j]=xorx[i][j-1] \oplus xorx[i+1][j]
\]

设\(maxx[l][r]\)表示区间\(\left [ l,r\right]\)内\(f(l,r)\)的最大值

\[maxx[l][r]=max(xorx[l][r],max(maxx[l][r-1],maxx[l+1][r]))
\]

即可

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n,xorx[5010][5010],maxx[5010][5010],q;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&xorx[i][i]),maxx[i][i]=xorx[i][i];
for(int l=2;l<=n;l++)
for(int i=1;i<=n-l+1;i++)
maxx[i][i+l-1]=xorx[i][i+l-1]=xorx[i][i+l-2]^xorx[i+1][i+l-1];
for(int l=2;l<=n;l++)
for(int i=1;i<=n-l+1;i++)
maxx[i][i+l-1]=max(maxx[i][i+l-2],max(maxx[i+1][i+l-1],maxx[i][i+l-1]));
scanf("%d",&q);
for(int i=1;i<=q;i++){
int l,r;
scanf("%d %d",&l,&r);
printf("%d\n",maxx[l][r]);
}
// for(int l=1;l<=n;l++)
// for(int i=1;i<=n-l+1;i++)
// printf("[%d,%d] = %d\n",i,i+l-1,xorx[i][i+l-1]);
return 0;
}

CF983B XOR-pyramid的更多相关文章

  1. 解题:CF983B pyramid

    题面 题目都告诉我们是“金字塔”了,不妨分析分析$f$的性质 $f(a_1,a_2)=f(a_1$ $xor$ $a_2)=a1$ $xor$ $a_2$ $f(a_1,a_2,a_3)=f(a_1$ ...

  2. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  3. 二分+DP+Trie HDOJ 5715 XOR 游戏

    题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  4. BZOJ 2115 【Wc2011】 Xor

    Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...

  5. xor和gates的专杀脚本

    前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...

  6. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  7. Xor && 线性基练习

    #include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...

  8. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  9. 异或链表(XOR linked list)

    异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点.可以参阅wiki 普通的双向链表 clas ...

  10. hdu 5661 Claris and XOR

    Claris and XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. 交替最小二乘ALS

    https://www.cnblogs.com/hxsyl/p/5032691.html http://www.cnblogs.com/skyEva/p/5570098.html 1. 基础回顾 矩阵 ...

  2. C#操作XML方法详解

    using System.Xml; //初始化一个xml实例 XmlDocument xml=new XmlDocument();   //导入指定xml文件 xml.Load(path); xml. ...

  3. 20165305 学习基础和C语言基础调查

    学习基础和C语言基础调查 <优秀的教学方法---做教练与做中学>心得 在<优秀的教学方法---做教练与做中学>文章中又一次提到了"做教练"这一学习方法,因为 ...

  4. eclipse 依赖别的 工程 断点进不去

    maven Debug 发现进不了断点. 点击右键-->Properties-->Java Compiler-->Classfile Generation, 勾选上Add line  ...

  5. centos下搭建Jenkins持续集成环境(安装jenkins)

    1.安装JDK yum install -y java 2.安装jenkins 添加Jenkins库到yum库,Jenkins将从这里下载安装. 1 wget -O /etc/yum.repos.d/ ...

  6. vue:自定义指令

    <div id="app"> <div v-lang="color">{{num}}</div> <button @c ...

  7. Python中*args和**kwargs 的简单使用

    # 在函数定义中使用*args和kwargs传递可变长参数. *args用作传递非命名键值可变长参数列表(位置参数); kwargs用作传递键值可变长参数列表# *args表示任何多个无名参数,它是一 ...

  8. The Little Prince-12/12

    The Little Prince-12/12 双十二,大家有没有买买买呢?宝宝双十一之后就吃土了,到现在,叶子都长出来了!!! 当你真的喜欢一个人的时候 就会想很多 会很容易办蠢事 说傻话 小王子要 ...

  9. 搭建ssm框架

    我现在在着手搭建一个项目ssm+angularsJs的框架 以下是目录结构 将所有的依赖全部引入到父工程中,然后在子工程中需要的时候,再引入,父工程只是用来引入依赖 <!-- 集中定义依赖版本号 ...

  10. linux下SVN忽略指定文件/文件夹

    http://www.cnblogs.com/fjping0606/p/4743009.html 1.配置SVN默认编辑器vi ~/.bash_profile最后一行加上:export SVN_EDI ...