【递推】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] D. XOR-pyramid
题意:定义
,对于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的更多相关文章
- 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 ...
- 【数论】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] C. Finite or not?
题意:给你一个分数,问你在b进制下能否化成有限小数. 条件:p/q假如已是既约分数,那么如果q的质因数分解集合是b的子集,就可以化成有限小数,否则不能. 参见代码:反复从q中除去b和q的公因子部分,并 ...
- 递推 Codeforces Round #186 (Div. 2) B. Ilya and Queries
题目传送门 /* 递推:用cnt记录前缀值,查询区间时,两个区间相减 */ #include <cstdio> #include <algorithm> #include &l ...
- Codeforces Round #483 Div. 1
A:首先将p和q约分.容易发现相当于要求存在k满足bk mod q=0,也即b包含q的所有质因子.当然不能直接分解质因数,考虑每次给q除掉gcd(b,q),若能将q除至1则说明合法.但这个辣鸡题卡常, ...
- Codeforces Round #483 (Div. 2) B题
B. Minesweeper time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 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 ...
- Codeforces Round #483 (Div. 2) B. Minesweeper
题目地址:http://codeforces.com/contest/984/problem/B 题目大意:扫雷游戏,给你一个n*m的地图,如果有炸弹,旁边的八个位置都会+1,问这幅图是不是正确的. ...
- 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 ...
- 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 ...
随机推荐
- 树形dp(C - Choosing Capital for Treeland CodeForces - 219D )
题目链接:https://cn.vjudge.net/contest/277955#problem/C 题目大意:输入n,代表有n个城市,然后再输入n-1条有向边,然后让你找出一个改变边数的最小值,使 ...
- Windows执行命令与下载文件总结
1.前言 在渗透或是病毒分析总是会遇到很多千奇百怪的下载文件和执行命令的方法. 2.实现方式 2.1.Powershell win2003.winXP不支持 $client = new-object ...
- 如何禁止Linux内核的-O2编译选项【转】
转自:http://blog.csdn.net/larryliuqing/article/details/8674274 http://lenky.info/2013/03/10/%E5%A6%82% ...
- 被我误解的max_connect_errors【转】
实为吾之愚见,望诸君酌之!闻过则喜,与君共勉 第一节 什么是max_connect_errors 一开始接触这个参数的时候,感觉他和max_connections的含义差不多,字面意思简单明了,这个 ...
- centos7.2系统没有eth0网卡
最近一直在学centos7.5系统,偶然看到虚拟机里有7.2系统所以想练习一下(其实7.2和7.5差不多),但是打开虚拟机之后,发现没有eth0网卡 那没有eth0网卡就无法远程连接ssh,既然遇到了 ...
- 学习记录:mongodb里插入整型值
=============================================== 2018/1/24_第1次修改 ccb_warlock == ...
- 转:vue-cli的webpack模板项目配置文件分析
转载地址:http://blog.csdn.net/hongchh/article/details/55113751 一.文件结构 本文主要分析开发(dev)和构建(build)两个过程涉及到的文件, ...
- java基础45 IO流技术(输入字符流/缓冲输入字符流)
一.输入字符流 1.1.输入字符流体系 ------| Reader:输入字符流的基类(抽象类) ----------| FileReader:向指定文件读取数据的输入字符流(把硬盘上的数据读取到程 ...
- 洛谷P2002消息扩散
传送门啦 这个题就是tarjan强连通分量与入度的例题了. 思路: 利用缩点的思想,先预处理一下所有的强连通分量,然后把每个强连通分量内的所有节点看做一个节点,然后处理一张新图,然后检查每个点的入度, ...
- ubuntu12.04安装ruby2.3
为了搭建github-pages博客,而github-pages后端依赖于ruby,且对版本有严格要求,自己尝试了各种姿势升级ruby2.3无果,最终在查阅了各种资料之后找到一个可行方案. icebu ...