<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Small-to-Large on k4i's blog</title><link>https://k4i.top/tags/small-to-large/</link><description>Recent content in Small-to-Large on k4i's blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>sky_io@outlook.com (K4i)</managingEditor><webMaster>sky_io@outlook.com (K4i)</webMaster><copyright>All content is subject to the license of &lt;a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank"&gt;CC BY-NC-SA 4.0&lt;/a&gt; .</copyright><lastBuildDate>Fri, 16 Feb 2024 19:05:00 +0800</lastBuildDate><atom:link href="https://k4i.top/tags/small-to-large/index.xml" rel="self" type="application/rss+xml"/><item><title>DSU on Tree (Sack)</title><link>https://k4i.top/posts/dsu-on-tree/</link><pubDate>Fri, 16 Feb 2024 19:05:00 +0800</pubDate><author>sky_io@outlook.com (K4i)</author><atom:modified>Sun, 26 Apr 2026 16:08:06 +0800</atom:modified><guid>https://k4i.top/posts/dsu-on-tree/</guid><description>&lt;h2 id="problem"&gt;the subtree-query problem&lt;/h2&gt;
&lt;p&gt;suppose every vertex of a rooted tree has a color. for every vertex \(v\), we want to answer:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;how many distinct colors appear in the subtree of \(v\)?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;a direct DFS for every query works, but it is too expensive. if we scan the whole subtree of each vertex independently, a chain of \(n\) vertices already costs&lt;/p&gt;
&lt;p&gt;\begin{equation}&lt;br /&gt;
1 + 2 + \cdots + n = O(n^2).&lt;br /&gt;
\end{equation}&lt;/p&gt;</description><dc:creator>K4i</dc:creator><media:content url="https://k4i.top//images/icons/binarytree.png" medium="image"><media:title type="html">featured image</media:title></media:content><category>dsu-on-tree</category><category>sack</category><category>tree</category><category>small-to-large</category><category>Data-Structure-and-Algorithm</category></item></channel></rss>