题意:定义,对于a数组的一个子区间[l,r],f[l,r]定义为对该子区间执行f操作的值。显然,有f[l,r]=f[l,r-1] xor f[l+1,r]。又定义ans[l,r]为满足l<=i<=j<=r的f[i,j]的最大值。多次询问你某些区间的ans值。

ans=max(f[l,r],ans[l,r-1],ans[l+1,r]),直接递推即可。

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

【递推】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] D. XOR-pyramid的更多相关文章

  1. Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]

    题目链接:http://codeforces.com/contest/984 A. Game time limit per test:2 seconds memory limit per test:5 ...

  2. 【数论】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] C. Finite or not?

    题意:给你一个分数,问你在b进制下能否化成有限小数. 条件:p/q假如已是既约分数,那么如果q的质因数分解集合是b的子集,就可以化成有限小数,否则不能. 参见代码:反复从q中除去b和q的公因子部分,并 ...

  3. 递推 Codeforces Round #186 (Div. 2) B. Ilya and Queries

    题目传送门 /* 递推:用cnt记录前缀值,查询区间时,两个区间相减 */ #include <cstdio> #include <algorithm> #include &l ...

  4. Codeforces Round #483 Div. 1

    A:首先将p和q约分.容易发现相当于要求存在k满足bk mod q=0,也即b包含q的所有质因子.当然不能直接分解质因数,考虑每次给q除掉gcd(b,q),若能将q除至1则说明合法.但这个辣鸡题卡常, ...

  5. Codeforces Round #483 (Div. 2) B题

    B. Minesweeper time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #483 (Div. 2)C题

    C. Finite or not? time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #483 (Div. 2) B. Minesweeper

    题目地址:http://codeforces.com/contest/984/problem/B 题目大意:扫雷游戏,给你一个n*m的地图,如果有炸弹,旁边的八个位置都会+1,问这幅图是不是正确的. ...

  8. Codeforces Round #483 (Div. 2) C. Finite or not?

    C. Finite or not? time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. Codeforces Round #483 (Div. 2) D. XOR-pyramid

    D. XOR-pyramid time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

随机推荐

  1. Java编程思想 4th 第1章 对象导论

    所有编程语言都提供抽象机制. 面向对象编程似乎是一种很好的编程思想和方式,面向对象编程中的对象简洁描述是:对象具有状态.行为和标识.状态指的是数据存储,存储的数据能反应状态:行为指的是方法,方法表示对 ...

  2. Vue 项目添加 promise polyfill

    1. 安装依赖 npm install es6-promise --save 2. 在 main.js 上面引入: import 'es6-promise/auto'

  3. python端口扫描

    简易版: #author:Blood_Zero #coding:utf-8 import socket import sys PortList=[21,22,23,25,80,135] # host= ...

  4. Qbot回归,已感染5.4万台计算机

    Qbot回归,已感染5.4万台计算机 近日,BAESystems的安全人员发表了一篇关于Qbot网络感知蠕虫回归的调查报告,指出已经感染了5.4万台计算机. FreeBuf百科 Qbot蠕虫,也叫Qa ...

  5. python 面试题3

    注:本面试题来源于网络. 1.python下多线程的限制以及多进程中传递参数的方式 python多线程有个全局解释器锁(global interpreter lock),这个锁的意思是任一时间只能有一 ...

  6. 将网址url中的参数转化为JSON格式

    网上方法很多,各种奇技淫巧,这里贴上一种较为正常的思路. 主要利用split对获取的字符串不断进行分割,最后获得所需要的格式. 代码如下 <!DOCTYPE html> <html ...

  7. qt 零星笔记

    1.qt中堆栈对象的销毁 名字不对,我不知道该取个什么名字,暂且这样吧 在linux c编程中谈到过进程的内存映像,一个进程在内存中的映像如下

  8. CKEDITOR的内容js转码,C#控制器解码接收

    <script type="text/javascript" src="<%=Url.Content("~/Resource/ckeditor/ck ...

  9. luoguP2735 电网 Electric Fences

    一道校内模拟赛遇见的题 ** 不会正解就真的很麻烦的 数学题 ** 有一种东西叫 皮克定理 发现的千古神犇: 姓名:George Alexander Pick(所以叫皮克定理呀 国籍:奥地利(蛤!竟然 ...

  10. sqlserver导出为EXcel--CSV格式

    DataTable dt = Connect.BindTable(" SELECT  名称,地址,当前日期  FROM  table   GROUP BY 名称,地址,当前日期 order ...