题意:定义,对于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. 判断最小生成树是否为一(krustra)

    题目链接:https://vjudge.net/contest/66965#problem/K 具体思路: 首先跑一遍最短路算法,然后将使用到的边标记一下,同时使用一个数组记录每一个权值出现的次数,如 ...

  2. 阿里面试回来,想和Java程序员谈一谈

    引言 其实本来真的没打算写这篇文章,主要是LZ得记忆力不是很好,不像一些记忆力强的人,面试完以后,几乎能把自己和面试官的对话都给记下来.LZ自己当初面试完以后,除了记住一些聊过的知识点以外,具体的内容 ...

  3. PHP 生成、识别二维码及安装相关扩展/工具

    2018-02-20 00:30:26  更新:推荐新扩展(极力推荐) 这篇文章里用的两个二维码扩展都有些问题和麻烦:phpqrcode(生成二维码)的源码有点小 bug: 而 php-zbarcod ...

  4. c# CTS 基础数据类型笔记

    C#中的基础数据类型并没有内置于c#语言中,而内置于.net freamework. C#有15个预定义类型,其中13个是值类型,两个是引用类型(string和object) 一.值类型 值类型 数据 ...

  5. 如何成为技术大牛——阿里CodeLife

    天天写业务代码的程序员,怎么成为技术大牛,开始写技术代码? 几个误区 跟着大牛,就可以成为大牛.首先,大牛时间很宝贵,不可能花很多时间去指导你:其次,简单的模仿大牛,只能学到表面知识,不可能成为大牛: ...

  6. python基础-各模块文章导航

    python基础学习日志day5-各模块文章导航 python基础学习日志day5---模块使用 http://www.cnblogs.com/lixiang1013/p/6832475.html p ...

  7. dede图集内容页调用

    {dede:productimagelist} <li> <img src="[field:imgsrc/]" width="92" heig ...

  8. 本地删除文件,git远程不同步删除

    git add -a 或 git add * 它能stages所有文件,包括之前删除的痕迹 git add . 只能stages新文件和被修改的文件,不会stages已被删除的文件 步骤如下: 1) ...

  9. Effective STL 学习笔记 Item 26: Prefer Iterator to reverse_iterator and const_rever_itertor

    Effective STL 学习笔记 Item 26: Prefer Iterator to reverse_iterator and const_rever_itertor */--> div ...

  10. linux下nc提交web报文问题

    1.用wireshark截取访问百度首页拿到的请求数据包: GET /index.php?tn=newbdie_bd_dg&bar= HTTP/1.1 Host: www.baidu.com ...