<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=09-%E8%BF%9B%E9%98%B6%E7%AE%97%E6%B3%95%2F05-%E7%A6%BB%E6%95%A3%E5%8C%96</id>
	<title>09-进阶算法/05-离散化 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=09-%E8%BF%9B%E9%98%B6%E7%AE%97%E6%B3%95%2F05-%E7%A6%BB%E6%95%A3%E5%8C%96"/>
	<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=09-%E8%BF%9B%E9%98%B6%E7%AE%97%E6%B3%95/05-%E7%A6%BB%E6%95%A3%E5%8C%96&amp;action=history"/>
	<updated>2026-05-20T22:23:21Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=09-%E8%BF%9B%E9%98%B6%E7%AE%97%E6%B3%95/05-%E7%A6%BB%E6%95%A3%E5%8C%96&amp;diff=434&amp;oldid=prev</id>
		<title>33DAI：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=09-%E8%BF%9B%E9%98%B6%E7%AE%97%E6%B3%95/05-%E7%A6%BB%E6%95%A3%E5%8C%96&amp;diff=434&amp;oldid=prev"/>
		<updated>2026-05-20T18:24:02Z</updated>

		<summary type="html">&lt;p&gt;批量导入三三文档&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 18:24的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l58&quot;&gt;第58行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第58行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:进阶算法]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:进阶算法]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:三三文档]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:三三文档]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key my_wiki:diff:1.41:old-399:rev-434:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=09-%E8%BF%9B%E9%98%B6%E7%AE%97%E6%B3%95/05-%E7%A6%BB%E6%95%A3%E5%8C%96&amp;diff=399&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=09-%E8%BF%9B%E9%98%B6%E7%AE%97%E6%B3%95/05-%E7%A6%BB%E6%95%A3%E5%8C%96&amp;diff=399&amp;oldid=prev"/>
		<updated>2026-05-20T18:12:17Z</updated>

		<summary type="html">&lt;p&gt;导入1个版本&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 18:12的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key my_wiki:diff:1.41:old-398:rev-399 --&gt;
&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=09-%E8%BF%9B%E9%98%B6%E7%AE%97%E6%B3%95/05-%E7%A6%BB%E6%95%A3%E5%8C%96&amp;diff=398&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=09-%E8%BF%9B%E9%98%B6%E7%AE%97%E6%B3%95/05-%E7%A6%BB%E6%95%A3%E5%8C%96&amp;diff=398&amp;oldid=prev"/>
		<updated>2026-05-20T16:50:33Z</updated>

		<summary type="html">&lt;p&gt;批量导入三三文档&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== 离散化 ==&lt;br /&gt;
&lt;br /&gt;
离散化将&amp;#039;&amp;#039;&amp;#039;很大但数量很少&amp;#039;&amp;#039;&amp;#039;的值映射到较小的连续整数，常用于权值数组、线段树等场景。&lt;br /&gt;
&lt;br /&gt;
=== 基本方法 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
vector&amp;lt;int&amp;gt; a = {100, 99999, 5, 100, 5}; // 原始数据&lt;br /&gt;
vector&amp;lt;int&amp;gt; b = a;&lt;br /&gt;
sort(b.begin(), b.end());&lt;br /&gt;
b.erase(unique(b.begin(), b.end()), b.end()); // 去重&lt;br /&gt;
&lt;br /&gt;
// 查询 x 离散化后的值（0-indexed）&lt;br /&gt;
auto get_id = [&amp;amp;](int x) -&amp;gt; int&lt;br /&gt;
{&lt;br /&gt;
    return lower_bound(b.begin(), b.end(), x) - b.begin();&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// a 离散化后: {1, 2, 0, 1, 0}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 手动离散化模板 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
struct Discrete&lt;br /&gt;
{&lt;br /&gt;
    int n;&lt;br /&gt;
    vector&amp;lt;int&amp;gt; val;&lt;br /&gt;
    Discrete(const vector&amp;lt;int&amp;gt;&amp;amp; a)&lt;br /&gt;
    {&lt;br /&gt;
        val = a;&lt;br /&gt;
        sort(val.begin(), val.end());&lt;br /&gt;
        val.erase(unique(val.begin(), val.end()), val.end());&lt;br /&gt;
        n = val.size() - 1; // 1-indexed&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // 查询 x 的排名（1-indexed）&lt;br /&gt;
    int id(int x)&lt;br /&gt;
    {&lt;br /&gt;
        return lower_bound(val.begin(), val.end(), x) - val.begin() + 1;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // 恢复原始值&lt;br /&gt;
    int val_of(int id)&lt;br /&gt;
    {&lt;br /&gt;
        return val[id - 1];&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 应用场景 ===&lt;br /&gt;
&lt;br /&gt;
* 权值线段树 / 树状数组（值域很大时先离散化）&lt;br /&gt;
* 扫描线算法&lt;br /&gt;
* 区间覆盖问题&lt;br /&gt;
&lt;br /&gt;
[[Category:进阶算法]]&lt;br /&gt;
[[Category:三三文档]]&lt;br /&gt;
&lt;/div&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
</feed>