题目大意:
  给你一个数列,求所有区间最大值和次大只异或的最大值。

思路:
  很容易想到一个O(n^2)的暴力。
  O(n)的单调栈做法似乎也很好想,不过考场上没想出来。
  对于数列上的某一个数,我们维护在它左边的比它大的单调递减序列。
  对于新加进来的一个数,我们把它作为最大值,对栈中比它小的数(次大值)取异或,并弹出这些数。

 #include<stack>
#include<cstdio>
#include<cctype>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
std::stack<unsigned> s;
int main() {
int n=getint();
s.push(getint());
unsigned ans=;
for(register int i=;i<n;i++) {
const unsigned &x=getint();
while(!s.empty()&&s.top()<=x) {
ans=std::max(ans,s.top()^x);
s.pop();
}
if(!s.empty()) ans=std::max(ans,s.top()^x);
s.push(x);
}
printf("%u\n",ans);
return ;
}

[SimpleOJ233]a xor b的更多相关文章

  1. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  2. 二分+DP+Trie HDOJ 5715 XOR 游戏

    题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. BZOJ 2115 【Wc2011】 Xor

    Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...

  4. xor和gates的专杀脚本

    前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...

  5. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  6. Xor && 线性基练习

    #include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...

  7. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  8. 异或链表(XOR linked list)

    异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点.可以参阅wiki 普通的双向链表 clas ...

  9. hdu 5661 Claris and XOR

    Claris and XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. 简易版jquery

    最近写了一个简易版的jquery   github地址:https://github.com/jiangzhenfei/Easy-Jquery 完成的方法: 1.$('#id') 2.extend扩展 ...

  2. 工作中常用的Git操作--------(一)

    今天主要记录一下平常工作当中使用的git操作: 1.git的安装这里省略: 2.git的操作指令: 在项目开发中,经常是拉去经理已经搭建好的一个项目,也就是给我们一个git地址.比如:http://g ...

  3. NASA: Seeing Jupiter(注视木星)

    This image of Jupiter’s southern hemisphere was captured by NASA’s Juno spacecraft on the outbound l ...

  4. Java八种基本类型

    boolean 二进制位: true ,false   byte 二进制位:8 -128 - 127   -2的7次方到2的7次方-1 char 二进制位:16 0 - 65535   short 二 ...

  5. dlmalloc(一)【转】

    转自:http://blog.csdn.net/ycnian/article/details/12971863 我们写过很多C程序了,经常会分配内存.记得刚学C语言时老师说过,可以向两个地方申请内存: ...

  6. juery下拉刷新,div加载更多元素并添加点击事件(二)

    buffer.append("<div class='col-xs-3 "+companyId+"' style='padding-left: 10px; padd ...

  7. 以太坊go-ethereum客户端查询交易列表(二)

    玩过比特币的朋友都知道,比特币是可以通过api(listtransactions)查询指定地址的历史交易的.但在eth中没有提供类似的查询api.今天这篇博客就简单介绍一下如果解决这个问题. 问题 以 ...

  8. Linux平台上SQLite数据库教程(一)——终端使用篇

    https://blog.csdn.net/u011192270/article/details/48031763 https://blog.csdn.net/fml1997/article/deta ...

  9. awk进阶

    整理的awk的小技巧 begin是要放在正则前面的,按照这个顺序: awk 'begin{} /.*?/ {action}end{}' file FS=':' 和 -F: 是等同的 -F 表示以 XX ...

  10. Codeforces Round #292 (Div. 1) C - Drazil and Park

    C - Drazil and Park 每个点有两个值Li 和 Bi,求Li + Rj (i < j) 的最大值,这个可以用线段树巧妙的维护.. #include<bits/stdc++. ...