AT_abc343_f [ABC343F] Second Largest Query 题解

分析

考虑乱搞。

对于求次大值,用线段树维护就行了。记录下每个区间的最大、次大值。则两个子区间的父区间的最大值就是这四个最大的,次大值就是这四个次大的。复杂度 O ( log ⁡ n ) O(\log n) O(logn)

求次大值的出现次数,乱搞就行了。因为带修,带修莫队或者分块有些麻烦。其实用线段树就行。在维护区间最大、次大值的时候,直接同时维护一下它们对应的出现次数,然后就是一个区间和的问题。复杂度 O ( log ⁡ n ) O(\log n) O(logn)

所以总的复杂度为 O ( n log ⁡ n ) O(n \log n) O(nlogn)不会有人去写莫队吧。

代码

这是带修莫队的代码

这是线段树的代码

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Key Features Get started with Rust to build scalable and high performance applications Enhance your application development skills using the power of Rust Discover the power of Rust when developing concurrent applications for large and scalable software Book Description Rust is the new, open source, fast, and safe systems programming language for the 21st century, developed at Mozilla Research, and with a steadily growing community. It was created to solve the dilemma between high-level, slow code with minimal control over the system, and low-level, fast code with maximum system control. It is no longer necessary to learn C/C++ to develop resource intensive and low-level systems applications. This book will give you a head start to solve systems programming and application tasks with Rust. We start off with an argumentation of Rust's unique place in today's landscape of programming languages. You'll install Rust and learn how to work with its package manager Cargo. The various concepts are introduced step by step: variables, types, functions, and control structures to lay the groundwork. Then we explore more structured data such as strings, arrays, and enums, and you'll see how pattern matching works. Throughout all this, we stress the unique ways of reasoning that the Rust compiler uses to produce safe code. Next we look at Rust's specific way of error handling, and the overall importance of traits in Rust code. The pillar of memory safety is treated in depth as we explore the various pointer kinds. Next, you'll see how macros can simplify code generation, and how to compose bigger projects with modules and crates. Finally, you'll discover how we can write safe concurrent code in Rust and interface with C programs, get a view of the Rust

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

harmis_yz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值