vijos紫色的手链单调栈
来源:互联网 发布:sql删除行 编辑:程序博客网 时间:2024/03/29 18:09
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=100010;
int n,a[maxn],r,q[maxn];
inline int read(){
int num=0;
char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') num=num*10+ch-'0',ch=getchar();
return num;
}
int main(){
int ans;
n=read();
for(int i=1;i<=n;i++) a[i]=read();
ans=a[1] xor a[2];
if(a[1]>a[2]){
q[++r]=a[1];
q[++r]=a[2];
}
else a[++r]=a[2];
for(int i=3;i<=n;i++){
ans=max(ans,a[i] xor q[r]);
//cout<<i<<' '<<r<<endl;
while(r>0&&a[i]>=q[r]){
--r;
ans=max(ans,a[i] xor q[r]);
//cout<<i<<' '<<r<<endl;
}
q[++r]=a[i];
}
cout<<ans<<endl;
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=100010;
int n,a[maxn],r,q[maxn];
inline int read(){
int num=0;
char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') num=num*10+ch-'0',ch=getchar();
return num;
}
int main(){
int ans;
n=read();
for(int i=1;i<=n;i++) a[i]=read();
ans=a[1] xor a[2];
if(a[1]>a[2]){
q[++r]=a[1];
q[++r]=a[2];
}
else a[++r]=a[2];
for(int i=3;i<=n;i++){
ans=max(ans,a[i] xor q[r]);
//cout<<i<<' '<<r<<endl;
while(r>0&&a[i]>=q[r]){
--r;
ans=max(ans,a[i] xor q[r]);
//cout<<i<<' '<<r<<endl;
}
q[++r]=a[i];
}
cout<<ans<<endl;
return 0;
}
阅读全文
1 0
- 【单调栈】Vijos P1926 紫色的手链
- vijos紫色的手链单调栈
- vijos 紫色的手链
- Vijos 1926 紫色的手链
- vijos 1580最大矩形(单调栈)
- 手链
- 手链
- 美丽的紫色
- 我的手链找不到了
- vijos 1243 单调队列优化dp
- Vijos 1243 初探单调队列优化DP
- Spket IDE, Ext开发人员的紫色匕首~
- Spket IDE, Ext开发人员的紫色匕首
- PS制作华丽的紫色立体字
- 单调栈的运用
- 单调栈的应用
- 单调栈的尝试
- 单调栈的总结
- 导航栏样式1
- 如何跳出令人窒息的职场死循环
- 数据时代来临,“我的乌托邦工作”是否还要继续?
- android. ARouter使用 theres no route matched! “找不到”!ARouter::No postcard!
- 设计模式大杂烩(24种设计模式的总结以及学习设计模式的几点建议)
- vijos紫色的手链单调栈
- 《剑指offer》刷题笔记(画图让抽象形象化):顺时针打印矩阵
- Android Studio Kotlin插件安装
- 求最长不重复子串---LeetCode3
- Java JVM 性能调优笔记
- 把html映射到外网
- 2017年10月17日 第八次总结
- 在Spring+Hibernate集成环境中使用EhCache缓存
- ajax打开新窗口window.open()被拦截的解决方法