<?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=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF%2F02-%E7%BA%BF%E6%AE%B5%E6%A0%91</id>
	<title>05-算法模板/02-线段树 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF%2F02-%E7%BA%BF%E6%AE%B5%E6%A0%91"/>
	<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF/02-%E7%BA%BF%E6%AE%B5%E6%A0%91&amp;action=history"/>
	<updated>2026-05-20T22:13:44Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF/02-%E7%BA%BF%E6%AE%B5%E6%A0%91&amp;diff=347&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF/02-%E7%BA%BF%E6%AE%B5%E6%A0%91&amp;diff=347&amp;oldid=prev"/>
		<updated>2026-05-20T18:12:10Z</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;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&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;2&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;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF/02-%E7%BA%BF%E6%AE%B5%E6%A0%91&amp;diff=346&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF/02-%E7%BA%BF%E6%AE%B5%E6%A0%91&amp;diff=346&amp;oldid=prev"/>
		<updated>2026-05-20T16:50:33Z</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;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 16:50的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&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;/table&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF/02-%E7%BA%BF%E6%AE%B5%E6%A0%91&amp;diff=247&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF/02-%E7%BA%BF%E6%AE%B5%E6%A0%91&amp;diff=247&amp;oldid=prev"/>
		<updated>2026-05-20T16:25:33Z</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;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 16:25的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&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;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF/02-%E7%BA%BF%E6%AE%B5%E6%A0%91&amp;diff=246&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=05-%E7%AE%97%E6%B3%95%E6%A8%A1%E6%9D%BF/02-%E7%BA%BF%E6%AE%B5%E6%A0%91&amp;diff=246&amp;oldid=prev"/>
		<updated>2026-05-20T16:22:29Z</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;
[https://oj.33dai.cn/p/P3374 【模板】树状数组 1]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;bits/stdc++.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
const int MAXN = 500000;&lt;br /&gt;
int n, m;&lt;br /&gt;
int a[MAXN + 5];&lt;br /&gt;
int t[MAXN * 4 + 5];&lt;br /&gt;
&lt;br /&gt;
void build(int now, int l, int r)&lt;br /&gt;
{&lt;br /&gt;
    if (l == r)&lt;br /&gt;
    {&lt;br /&gt;
        t[now] = a[l];&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    build(now * 2, l, mid);&lt;br /&gt;
    build(now * 2 + 1, mid + 1, r);&lt;br /&gt;
    t[now] = t[now * 2] + t[now * 2 + 1];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void update(int now, int l, int r, int x, int y)&lt;br /&gt;
{&lt;br /&gt;
    if (l == r)&lt;br /&gt;
    {&lt;br /&gt;
        t[now] += y;&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    if (x &amp;lt;= mid)&lt;br /&gt;
        update(now * 2, l, mid, x, y);&lt;br /&gt;
    if (x &amp;gt; mid)&lt;br /&gt;
        update(now * 2 + 1, mid + 1, r, x, y);&lt;br /&gt;
    t[now] = t[now * 2] + t[now * 2 + 1];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int query(int now, int l, int r, int x, int y)&lt;br /&gt;
{&lt;br /&gt;
    if (x &amp;lt;= l &amp;amp;&amp;amp; r &amp;lt;= y)&lt;br /&gt;
        return t[now];&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    int res = 0;&lt;br /&gt;
    if (x &amp;lt;= mid)&lt;br /&gt;
        res += query(now * 2, l, mid, x, y);&lt;br /&gt;
    if (y &amp;gt;= mid + 1)&lt;br /&gt;
        res += query(now * 2 + 1, mid + 1, r, x, y);&lt;br /&gt;
    return res;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    ios::sync_with_stdio(false);&lt;br /&gt;
    cin.tie(0);&lt;br /&gt;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;&lt;br /&gt;
    for (int i = 1; i &amp;lt;= n; i++)&lt;br /&gt;
        cin &amp;gt;&amp;gt; a[i];&lt;br /&gt;
    build(1, 1, n);&lt;br /&gt;
    for (int i = 1; i &amp;lt;= m; i++)&lt;br /&gt;
    {&lt;br /&gt;
        int op, x, y;&lt;br /&gt;
        cin &amp;gt;&amp;gt; op;&lt;br /&gt;
        if (op == 1)&lt;br /&gt;
        {&lt;br /&gt;
            cin &amp;gt;&amp;gt; x &amp;gt;&amp;gt; y;&lt;br /&gt;
            update(1, 1, n, x, y);&lt;br /&gt;
        }&lt;br /&gt;
        if (op == 2)&lt;br /&gt;
        {&lt;br /&gt;
            cin &amp;gt;&amp;gt; x &amp;gt;&amp;gt; y;&lt;br /&gt;
            cout &amp;lt;&amp;lt; query(1, 1, n, x, y) &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 区间修改、区间查询（懒标记） ==&lt;br /&gt;
&lt;br /&gt;
[https://oj.33dai.cn/p/P3372 【模板】线段树 1]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;bits/stdc++.h&amp;gt;&lt;br /&gt;
#define int long long&lt;br /&gt;
using namespace std;&lt;br /&gt;
const int MAXN = 100000;&lt;br /&gt;
int n, m;&lt;br /&gt;
int a[MAXN + 5];&lt;br /&gt;
int t[MAXN * 4 + 5], lazy[MAXN * 4 + 5];&lt;br /&gt;
&lt;br /&gt;
void build(int now, int l, int r)&lt;br /&gt;
{&lt;br /&gt;
    if (l == r)&lt;br /&gt;
    {&lt;br /&gt;
        t[now] = a[l];&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    build(now * 2, l, mid);&lt;br /&gt;
    build(now * 2 + 1, mid + 1, r);&lt;br /&gt;
    t[now] = t[now * 2] + t[now * 2 + 1];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void down(int now, int l, int r)&lt;br /&gt;
{&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    lazy[now * 2] += lazy[now];&lt;br /&gt;
    t[now * 2] += (mid - l + 1) * lazy[now];&lt;br /&gt;
    lazy[now * 2 + 1] += lazy[now];&lt;br /&gt;
    t[now * 2 + 1] += (r - mid) * lazy[now];&lt;br /&gt;
    lazy[now] = 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void update(int now, int l, int r, int x, int y, int z)&lt;br /&gt;
{&lt;br /&gt;
    if (x &amp;lt;= l &amp;amp;&amp;amp; r &amp;lt;= y)&lt;br /&gt;
    {&lt;br /&gt;
        t[now] += (r - l + 1) * z;&lt;br /&gt;
        lazy[now] += z;&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    down(now, l, r);&lt;br /&gt;
    if (x &amp;lt;= mid)&lt;br /&gt;
        update(now * 2, l, mid, x, y, z);&lt;br /&gt;
    if (y &amp;gt; mid)&lt;br /&gt;
        update(now * 2 + 1, mid + 1, r, x, y, z);&lt;br /&gt;
    t[now] = t[now * 2] + t[now * 2 + 1];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int query(int now, int l, int r, int x, int y)&lt;br /&gt;
{&lt;br /&gt;
    if (x &amp;lt;= l &amp;amp;&amp;amp; r &amp;lt;= y)&lt;br /&gt;
        return t[now];&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    down(now, l, r);&lt;br /&gt;
    int res = 0;&lt;br /&gt;
    if (x &amp;lt;= mid)&lt;br /&gt;
        res += query(now * 2, l, mid, x, y);&lt;br /&gt;
    if (y &amp;gt; mid)&lt;br /&gt;
        res += query(now * 2 + 1, mid + 1, r, x, y);&lt;br /&gt;
    return res;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
signed main()&lt;br /&gt;
{&lt;br /&gt;
    ios::sync_with_stdio(false);&lt;br /&gt;
    cin.tie(0);&lt;br /&gt;
    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;&lt;br /&gt;
    for (int i = 1; i &amp;lt;= n; i++)&lt;br /&gt;
        cin &amp;gt;&amp;gt; a[i];&lt;br /&gt;
    build(1, 1, n);&lt;br /&gt;
    while (m--)&lt;br /&gt;
    {&lt;br /&gt;
        int op, x, y, z;&lt;br /&gt;
        cin &amp;gt;&amp;gt; op;&lt;br /&gt;
        if (op == 1)&lt;br /&gt;
        {&lt;br /&gt;
            cin &amp;gt;&amp;gt; x &amp;gt;&amp;gt; y &amp;gt;&amp;gt; z;&lt;br /&gt;
            update(1, 1, n, x, y, z);&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            cin &amp;gt;&amp;gt; x &amp;gt;&amp;gt; y;&lt;br /&gt;
            cout &amp;lt;&amp;lt; query(1, 1, n, x, y) &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return 0;&lt;br /&gt;
}&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;
#include &amp;lt;bits/stdc++.h&amp;gt;&lt;br /&gt;
#define int long long&lt;br /&gt;
using namespace std;&lt;br /&gt;
const int MAXN = 100000;&lt;br /&gt;
int n, m, p;&lt;br /&gt;
int a[MAXN + 5];&lt;br /&gt;
int t[MAXN * 4 + 5];&lt;br /&gt;
int lazyAdd[MAXN * 4 + 5], lazyMul[MAXN * 4 + 5];&lt;br /&gt;
&lt;br /&gt;
void build(int now, int l, int r)&lt;br /&gt;
{&lt;br /&gt;
    lazyAdd[now] = 0;&lt;br /&gt;
    lazyMul[now] = 1;&lt;br /&gt;
    if (l == r)&lt;br /&gt;
    {&lt;br /&gt;
        t[now] = a[l];&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    build(now * 2, l, mid);&lt;br /&gt;
    build(now * 2 + 1, mid + 1, r);&lt;br /&gt;
    t[now] = (t[now * 2] + t[now * 2 + 1]) % p;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void down(int now, int l, int r)&lt;br /&gt;
{&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    int add = lazyAdd[now], mul = lazyMul[now];&lt;br /&gt;
&lt;br /&gt;
    lazyMul[now * 2] = lazyMul[now * 2] * mul % p;&lt;br /&gt;
    lazyAdd[now * 2] = (lazyAdd[now * 2] * mul + add) % p;&lt;br /&gt;
    t[now * 2] = (t[now * 2] * mul + (mid - l + 1) * add) % p;&lt;br /&gt;
&lt;br /&gt;
    lazyMul[now * 2 + 1] = lazyMul[now * 2 + 1] * mul % p;&lt;br /&gt;
    lazyAdd[now * 2 + 1] = (lazyAdd[now * 2 + 1] * mul + add) % p;&lt;br /&gt;
    t[now * 2 + 1] = (t[now * 2 + 1] * mul + (r - mid) * add) % p;&lt;br /&gt;
&lt;br /&gt;
    lazyAdd[now] = 0;&lt;br /&gt;
    lazyMul[now] = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void update_add(int now, int l, int r, int x, int y, int z)&lt;br /&gt;
{&lt;br /&gt;
    if (x &amp;lt;= l &amp;amp;&amp;amp; r &amp;lt;= y)&lt;br /&gt;
    {&lt;br /&gt;
        t[now] = (t[now] + (r - l + 1) * z) % p;&lt;br /&gt;
        lazyAdd[now] = (lazyAdd[now] + z) % p;&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    down(now, l, r);&lt;br /&gt;
    if (x &amp;lt;= mid)&lt;br /&gt;
        update_add(now * 2, l, mid, x, y, z);&lt;br /&gt;
    if (y &amp;gt; mid)&lt;br /&gt;
        update_add(now * 2 + 1, mid + 1, r, x, y, z);&lt;br /&gt;
    t[now] = (t[now * 2] + t[now * 2 + 1]) % p;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void update_mul(int now, int l, int r, int x, int y, int z)&lt;br /&gt;
{&lt;br /&gt;
    if (x &amp;lt;= l &amp;amp;&amp;amp; r &amp;lt;= y)&lt;br /&gt;
    {&lt;br /&gt;
        t[now] = t[now] * z % p;&lt;br /&gt;
        lazyMul[now] = lazyMul[now] * z % p;&lt;br /&gt;
        lazyAdd[now] = lazyAdd[now] * z % p;&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    down(now, l, r);&lt;br /&gt;
    if (x &amp;lt;= mid)&lt;br /&gt;
        update_mul(now * 2, l, mid, x, y, z);&lt;br /&gt;
    if (y &amp;gt; mid)&lt;br /&gt;
        update_mul(now * 2 + 1, mid + 1, r, x, y, z);&lt;br /&gt;
    t[now] = (t[now * 2] + t[now * 2 + 1]) % p;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int query(int now, int l, int r, int x, int y)&lt;br /&gt;
{&lt;br /&gt;
    if (x &amp;lt;= l &amp;amp;&amp;amp; r &amp;lt;= y)&lt;br /&gt;
        return t[now];&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    down(now, l, r);&lt;br /&gt;
    int res = 0;&lt;br /&gt;
    if (x &amp;lt;= mid)&lt;br /&gt;
        res = (res + query(now * 2, l, mid, x, y)) % p;&lt;br /&gt;
    if (y &amp;gt; mid)&lt;br /&gt;
        res = (res + query(now * 2 + 1, mid + 1, r, x, y)) % p;&lt;br /&gt;
    return res;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 动态开点线段树（权值线段树） ==&lt;br /&gt;
&lt;br /&gt;
[https://oj.33dai.cn/p/P1168 中位数]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;bits/stdc++.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
const int MAXN = 100000;&lt;br /&gt;
const int MAXAI = 1&amp;#039;000&amp;#039;000&amp;#039;000;&lt;br /&gt;
int n, a[MAXN + 5];&lt;br /&gt;
int tot = 1;&lt;br /&gt;
int lson[MAXN * 30 + 5], rson[MAXN * 30 + 5];&lt;br /&gt;
int t[MAXN * 30 + 5];&lt;br /&gt;
&lt;br /&gt;
void update(int now, int l, int r, int x, int y)&lt;br /&gt;
{&lt;br /&gt;
    if (l == r)&lt;br /&gt;
    {&lt;br /&gt;
        t[now] += y;&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    if (x &amp;lt;= mid)&lt;br /&gt;
    {&lt;br /&gt;
        if (!lson[now])&lt;br /&gt;
            lson[now] = ++tot;&lt;br /&gt;
        update(lson[now], l, mid, x, y);&lt;br /&gt;
    }&lt;br /&gt;
    if (x &amp;gt; mid)&lt;br /&gt;
    {&lt;br /&gt;
        if (!rson[now])&lt;br /&gt;
            rson[now] = ++tot;&lt;br /&gt;
        update(rson[now], mid + 1, r, x, y);&lt;br /&gt;
    }&lt;br /&gt;
    t[now] = t[lson[now]] + t[rson[now]];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// 在线段树上二分，找第 k 小&lt;br /&gt;
int kth(int now, int l, int r, int k)&lt;br /&gt;
{&lt;br /&gt;
    if (l == r)&lt;br /&gt;
        return l;&lt;br /&gt;
    int mid = (l + r) / 2;&lt;br /&gt;
    if (t[lson[now]] &amp;gt;= k)&lt;br /&gt;
        return kth(lson[now], l, mid, k);&lt;br /&gt;
    return kth(rson[now], mid + 1, r, k - t[lson[now]]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:算法模板]]&lt;br /&gt;
[[Category:三三文档]]&lt;/div&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
</feed>