Actually I think problem statement is somewhat misleading. No need to mention range [L, R] at all.

The intention is a variation to "Largest Rectangle" which is a classic stack problem on LeetCode.

But you need to run Largest Rectangle twice: increased and decreased.

#include <cmath>
#include <stack>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; int main() {
int n; cin >> n;
vector<int> in(n);
for(int i = ; i < n; i ++)
cin >> in[i]; int ret = ;
{
in.push_back();
stack<int> stk;
for (int i = ; i < in.size(); i++)
{
if (stk.empty() || in[i] > stk.top())
{
stk.push(in[i]);
}
else
{
int lastV = stk.top(); stk.pop();
if (!stk.empty())
{
ret = std::max(ret, (lastV ^ stk.top()));
//cout << lastV << "-" << stk.top() << "=" << (lastV ^ stk.top()) << endl;
}
i--;
}
}
in.pop_back();
}
{ stack<int> stk;
in.insert(in.begin(), );
for (int i = in.size() - ; i >= ; i --)
{
if (stk.empty() || in[i] > stk.top())
{
stk.push(in[i]);
}
else
{
int lastV = stk.top(); stk.pop();
if (!stk.empty())
{
ret = std::max(ret, (lastV ^ stk.top()));
//cout << lastV << "-" << stk.top() << "=" << (lastV ^ stk.top()) << endl;
}
i++;
}
}
} cout << ret << endl;
return ;
}

最新文章

  1. gcc中__builtin_return_address和__VA_ARGS__
  2. 模板方法模式(Template Method)
  3. C# winform Listbox添加和删除items
  4. [kuangbin带你飞]专题十 匹配问题
  5. 4.python中的用户交互
  6. C/C++ unit testing tools (39 found)---reference
  7. Eclipse安装SVN插件的方法( 手动安装)
  8. 【现代程序设计】【Homework-01】
  9. 如何分析apache日志[access_log(访问日志)和error_log(错误日志)]
  10. jQuery学习-事件之绑定事件(三)
  11. vga显示彩条
  12. 基于jquery开发的UI框架整理分析
  13. Spring Cloud Ribbon 整合 Hystrix
  14. 【第十九篇】laydate设置起始时间,laydate设置开始时间和结束时间
  15. python_Tkinter1
  16. 如何更改github工程的语言属性
  17. 纯JS编写打地鼠游戏
  18. jsp泛型支持
  19. 用jQuery实现ajax总结以及跨域问题
  20. libcur+openssl的编译,使之支持SSL&lt;转&gt;

热门文章

  1. 分布式消息队列kafka系列介绍 — 核心API介绍及实例
  2. word文档快速取消图片的链接
  3. CentOS云服务器数据盘分区和格式化
  4. 自己写getElementsByClass()方法
  5. HDU 4497 数论+组合数学
  6. leetcode 101 Symmetric Tree ----- java
  7. leetcode 91 Decode Ways ----- java
  8. puppet安装配置及使用
  9. Codeforces Round #104 (Div. 1)
  10. UVA-11235 Frequent values (RMQ)