当前位置:网站首页>codeforces: B. Maximum Xor Secondary【Monotone Stack】
codeforces: B. Maximum Xor Secondary【Monotone Stack】
2022-08-05 19:52:00 【Looking Back at the White Speed Dragon King】

Analysis
When we fix a next largest element (every one is possible)
The largest element is either on the left or on the right
It is the first one on the left or right that can be found using a monotonic stackA number larger than the current next-largest value
Then record 2n times such a maximum-sub-largest combination
ac code
import sysinput = sys.stdin.readlinen = int(input())s = list(map(int, input().split()))ans = 0st = []# every v can be the second max, max on left or rightfor v in s:# decreasing stack# st[-1] second max, v max(max on right)while st and st[-1] <v:ans = max(st.pop() ^ v, ans)# v second max, st[-1] max(max on left)if st:ans = max(st[-1]^ v, ans)st.append(v)print(ans) Summary
Monotone stack messing
边栏推荐
猜你喜欢
随机推荐
IDEA使用问题-01 无法使用ibus输入中文
C language programming introduction to learn six steps, six steps to take you into the C language
Vim命令总结
【代码解读】超详细,YOLOV5之build_targets函数解读。
JS高阶(二)Symbol
在 ETH 上做多?你有义务阅读这篇文章
How to change the boot sound of Win11?
Rust学习笔记:3.1 变量与可变性
软件测试面试(五)
27. Remove elements - double pointer method
HCIP第十七天笔记(接口状态的变化、STP配置、802.1W的改进点、MSTP)
分享几个YYDS的Pycharm插件
RAID磁盘阵列详解
151. 颠倒字符串中的单词-双指针法
如何更换war和jar包中的文件
C# 事件(Event)用法
SwiftUI案例:Lottie载入动画
给根目录扩容
C语言中的三大自建类型
【无标题】









