JOZJ5185. 【NOIP2017提高组模拟6.30】tty's sequence
来源:互联网 发布:施华蔻黑胶和银胶 知乎 编辑:程序博客网 时间:2024/06/06 00:07
分析
很显然,或是越或越大,不会减少的,
所以,或的最大值就是全部或起来。
而与是相反的,越来越小,
所以刚刚好是k个时答案最大。
现在我们就考虑如何快速查询某个区间的与。
我们可以开一个数据s[0..32],
每加入或者删除一个数,我们可以快速修改数组s,从而快速得出一个区间的与。
用线段树或者RMQ维护也是可以的。
code
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#define N 1000003#define M 33using namespace std;int t[M],n,m,k,ans,mx;int a[N],z[M];char ch;void read(int &n){ n=0; ch=getchar(); while(ch<'0' || ch>'9')ch=getchar(); while('0'<=ch && ch<='9')n=n*10+ch-'0',ch=getchar();}int main(){ z[0]=1; for(int i=1;i<33;i++) z[i]=z[i-1]*2; read(n);read(k); for(int i=1;i<=n;i++) read(a[i]),ans=ans|a[i]; printf("%d ",ans); for(int i=1;i<=k;i++) for(int j=0;j<M;j++) if((a[i]&z[j])==0)t[j]++; mx=0; for(int j=0;j<M;j++) if(!t[j])mx+=z[j]; for(int i=k+1;i<=n;i++) { for(int j=0;j<M;j++) { if((a[i-k]&z[j])==0)t[j]--; if((a[i]&z[j])==0)t[j]++; } ans=0; for(int j=0;j<M;j++) if(!t[j])ans+=z[j]; mx=max(mx,ans); } printf("%d\n",mx);}
阅读全文
0 0
- JOZJ5185. 【NOIP2017提高组模拟6.30】tty's sequence
- JZOJ 5185. 【NOIP2017提高组模拟6.30】tty's sequence
- 【NOIP2017提高组模拟6.30】tty's home
- 【ZJOJ5186】【NOIP2017提高组模拟6.30】tty's home
- JZOJ 5186. 【NOIP2017提高组模拟6.30】tty's home
- 【NOIP2017提高组模拟6.30】tty's maze
- JZOJ5187. 【NOIP2017提高组模拟6.30】tty's maze
- [JZOJ5187]【NOIP2017提高组模拟6.30】tty's maze
- [NOIP2017模拟]Sequence
- 4920. 【NOIP2017提高组模拟12.10】降雷皇
- 【NOIP2017提高组模拟12.10】神炎皇
- 【NOIP2017提高组模拟12.10】神炎皇
- 【NOIP2017提高组模拟12.10】幻魔皇
- JZOJ4919. 【NOIP2017提高组模拟12.10】神炎皇
- 【NOIP2017提高组模拟12.10】神炎皇
- 【NOIP2017提高组模拟12.10】幻魔皇
- 【NOIP2017提高组模拟12.10】幻魔皇
- 【JZOJ4921】【NOIP2017提高组模拟12.10】幻魔皇
- 创建爬虫----遍历单个域名爬取赶集网
- h5学习笔记:标签页 after
- mciSendString的介绍
- Mysql技术内幕InnoDB存储引擎读书笔记--《四》表
- anaconda 安装talib
- JOZJ5185. 【NOIP2017提高组模拟6.30】tty's sequence
- HQL查询
- javase
- 百度地图申请AK
- 萌新报道,立贴为证
- HEVC代码学习19:MV、MVD、MVP概念解析
- Git错误non-fast-forward后的冲突解决
- SqEl基础2
- Python基础--列表类型