CF983B XOR-pyramid
设\(xorx[l][r]\)表示题目中\(f(l,r)\)的值,则可以得出
\]
设\(maxx[l][r]\)表示区间\(\left [ l,r\right]\)内\(f(l,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的更多相关文章
- 解题: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$ ...
- [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 ...
- 二分+DP+Trie HDOJ 5715 XOR 游戏
题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- BZOJ 2115 【Wc2011】 Xor
Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...
- xor和gates的专杀脚本
前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...
- Codeforces617 E . XOR and Favorite Number(莫队算法)
XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...
- Xor && 线性基练习
#include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...
- BC之Claris and XOR
http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...
- 异或链表(XOR linked list)
异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点.可以参阅wiki 普通的双向链表 clas ...
- hdu 5661 Claris and XOR
Claris and XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
随机推荐
- javascript(二):数据类型&数值
第一部分:数据类型 javascript数据类型通常来说是6种(ES6新增第七种Symbol类型) number:数值 string:字符串 boolean:布尔类型,true或false undef ...
- Android开发随笔记_1
1):android:configChanges="keyboardHidden|orientation":配置的好处:一般在AndroidManifest.xml文件中都没有使用 ...
- html5-相对定位
*{ margin: 0px; padding: 0px;}div{ width: 300px; height: 300px;}#div1{ background: rg ...
- Python - 4. Control Structures
From:http://interactivepython.org/courselib/static/pythonds/Introduction/ControlStructures.html Cont ...
- Spring 无缝整合 quartz
关键步骤: 1. 配置 SchedulerFactoryBean <bean class="org.springframework.scheduling.quartz.Schedule ...
- python 内置函数enumerate()
enumerate() 函数用于将一个可遍历的数据对象(如列表.元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中.在python 3中返回一个生成器,代码如下: a ...
- 设计模式之Observer(观察者)(转)
Java深入到一定程度,就不可避免的碰到设计模式(design pattern)这一概念,了解设计模式,将使自己对java中的接口或抽象类应用有更深的理解.设计模式在java的中型系统中应用广泛,遵循 ...
- JS中的函数节流throttle详解和优化
JS中的函数节流throttle详解和优化在前端开发中,有时会为页面绑定resize事件,或者为一个页面元素绑定拖拽事件(mousemove),这种事件有一个特点,在一个正常的操作中,有可能在一个短的 ...
- PHP json_encode函数中需要注意的地方
在php中使用 json_encode() 内置函数可以使用得php中的数据更好的与其它语言传递与使用. 这个函数的功能是将数组转换成json数据存储格式: 1 <?php 2 $arr=arr ...
- Python3自定义日志类 mylog
#encoding=utf-8 import os, sysimport datetimeimport time class Mylog(object): # 根文件夹 root_dir = s ...