<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Leetcode on 随记</title><link>https://blog.liuyi2026.asia/zh/tags/leetcode/</link><description>Recent content in Leetcode on 随记</description><generator>Hugo</generator><language>zh</language><lastBuildDate>Thu, 15 May 2025 09:43:53 +0800</lastBuildDate><atom:link href="https://blog.liuyi2026.asia/zh/tags/leetcode/index.xml" rel="self" type="application/rss+xml"/><item><title>154【杂项】算竞常用_C++_STL_用法</title><link>https://blog.liuyi2026.asia/zh/docs/technology/cpp/leetcode/</link><pubDate>Thu, 15 May 2025 09:43:53 +0800</pubDate><guid>https://blog.liuyi2026.asia/zh/docs/technology/cpp/leetcode/</guid><description>&lt;p>&lt;strong>C++ 标准模板库 (STL, Standard Template Library)&lt;/strong>：包含一些常用数据结构与算法的模板的 C++ 软件库。其包含四个组件——算法 (Algorithms)、容器 (Containers)、仿函数 (Functors)、迭代器 (Iterators).&lt;/p>
&lt;p>示例：&lt;/p>
&lt;ul>
&lt;li>算法：&lt;code>sort(a.begin(), a.end())&lt;/code>&lt;/li>
&lt;li>容器：&lt;code>priority_queue&amp;lt;int&amp;gt; pque&lt;/code>&lt;/li>
&lt;li>仿函数：&lt;code>greater&amp;lt;int&amp;gt;()&lt;/code>&lt;/li>
&lt;li>迭代器：&lt;code>vector&amp;lt;int&amp;gt;::iterator it = a.begin()&lt;/code>&lt;/li>
&lt;/ul>
&lt;h1 id="1-前言">1 前言&lt;a class="anchor" href="#1-%e5%89%8d%e8%a8%80">#&lt;/a>&lt;/h1>
&lt;p>STL 作为一个封装良好，性能合格的 C++ 标准库，在算法竞赛中运用极其常见。灵活且正确使用 STL 可以节省非常多解题时间，这一点不仅是由于可以直接调用，还是因为它封装良好，可以让代码的可读性变高，解题思路更清晰，调试过程 &lt;del>往往&lt;/del> 更顺利。&lt;/p>
&lt;p>不过 STL 毕竟使用了很多复杂的结构来实现丰富的功能，它的效率往往是比不上自己手搓针对特定题目的数据结构与算法的。因此，STL 的使用相当于使用更长的运行时间换取更高的编程效率。因此，在实际比赛中要权衡 STL 的利弊，不过这一点就得靠经验了。&lt;/p>
&lt;p>接下来，我会分享在算法竞赛中常用的 STL 容器和算法，对于函数和迭代器，就不着重展开讲了。&lt;/p>
&lt;h1 id="2-常用容器">2 常用容器&lt;a class="anchor" href="#2-%e5%b8%b8%e7%94%a8%e5%ae%b9%e5%99%a8">#&lt;/a>&lt;/h1>
&lt;h2 id="21-内容总览">2.1 内容总览&lt;a class="anchor" href="#21-%e5%86%85%e5%ae%b9%e6%80%bb%e8%a7%88">#&lt;/a>&lt;/h2>
&lt;p>打勾的是本次将会详细讲解的，加粗的是算法竞赛中有必要学习的。&lt;/p>
&lt;ul>
&lt;li>
&lt;p>顺序容器&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;input disabled="" type="checkbox"> &lt;strong>array&lt;/strong>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;input checked="" disabled="" type="checkbox"> &lt;strong>vector&lt;/strong>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;input disabled="" type="checkbox"> &lt;strong>deque&lt;/strong>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;input disabled="" type="checkbox"> forward_list&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;input disabled="" type="checkbox"> &lt;strong>list&lt;/strong>&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>关联容器&lt;/p>
&lt;ul>
&lt;li>&lt;input checked="" disabled="" type="checkbox"> &lt;strong>set&lt;/strong>&lt;/li>
&lt;li>&lt;input checked="" disabled="" type="checkbox"> &lt;strong>map&lt;/strong>&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> &lt;strong>multiset&lt;/strong>&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> &lt;strong>multimap&lt;/strong>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>无序关联容器&lt;/p>
&lt;ul>
&lt;li>&lt;input disabled="" type="checkbox"> &lt;strong>unordered_set&lt;/strong>&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> &lt;strong>unordered_map&lt;/strong>&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> &lt;strong>unordered_multiset&lt;/strong>&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> &lt;strong>unordered_multimap&lt;/strong>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>容器适配器&lt;/p></description></item></channel></rss>