<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Throne</title>
    <link>https://lifexoryoung.cn/</link>
    
    <atom:link href="https://lifexoryoung.cn/rss2.xml" rel="self" type="application/rss+xml"/>
    
    <description>读一些无用的书，做一些无用的事，花一些无用的时间，都是为了在一切已知之外，保留一个超越自己的机会，人生中一些很了不起的变化，就是来自这种时刻。——梁文道</description>
    <pubDate>Thu, 06 Feb 2025 05:26:04 GMT</pubDate>
    <generator>http://hexo.io/</generator>
    
    <item>
      <title>2024CCPC深圳站组队赛题解</title>
      <link>https://lifexoryoung.cn/2024/10/18/2024CCPC%E6%B7%B1%E5%9C%B3%E7%AB%99%E7%BB%84%E9%98%9F%E8%B5%9B%E9%A2%98%E8%A7%A3/</link>
      <guid>https://lifexoryoung.cn/2024/10/18/2024CCPC%E6%B7%B1%E5%9C%B3%E7%AB%99%E7%BB%84%E9%98%9F%E8%B5%9B%E9%A2%98%E8%A7%A3/</guid>
      <pubDate>Fri, 18 Oct 2024 08:02:32 GMT</pubDate>
      
        
        
      <description>&lt;span id=&quot;more&quot;&gt;&lt;/span&gt;
&lt;h3 id=&quot;A-一道好题&quot;&gt;&lt;a href=&quot;#A-一道好题&quot; class=&quot;headerlink&quot; title=&quot;A:一道好题&quot;&gt;&lt;/a&gt;A:一道好题&lt;/h3&gt;&lt;h4 id=&quot;Description&quot;&gt;&lt;a href=&quot;#De</description>
        
      
      
      
      <content:encoded><![CDATA[<span id="more"></span><h3 id="A-一道好题"><a href="#A-一道好题" class="headerlink" title="A:一道好题"></a>A:一道好题</h3><h4 id="Description"><a href="#Description" class="headerlink" title="Description"></a>Description</h4><p>一道好题应该有一个简洁的题面。</p><p>有一个长度为 n，初始全为 0 的序列 a，另有一个长度为 n 的序列 b，你希望将 a 变成 b，你可以执行如下两种操作：</p><p>1 x：将 a 中所有值为 x 的数 +1。</p><p>2 x：将 a 中下标为 x 的数 +1。</p><p>你不需要最小化操作次数，但只能使用最多 20000 次操作。</p><h4 id="Input"><a href="#Input" class="headerlink" title="Input"></a>Input</h4><p>第一行一个正整数 n（1≤n≤1000）。</p><p>第二行 n 个非负整数 b1,⋯,bn（0≤bi≤n）描述序列 b。</p><h4 id="Output"><a href="#Output" class="headerlink" title="Output"></a>Output</h4><p>第一行一个整数 k 表示操作次数，你需要保证 0≤k≤20000。</p><p>之后 k 行每行两个整数 1 x 或 2 x，表示一次操作。对于 1 x 类型的操作，你需要保证 0≤x≤n，对于 2 x 类型的操作，你需要保证 1≤x≤n。</p><h4 id="分析："><a href="#分析：" class="headerlink" title="分析："></a>分析：</h4><p>第一次做的时候 各种贪心，分块超次数了。</p><p>首先看到操作次数 $20000&gt;=n*logn$ ，所以可以大约往出来算法运行次数为 $nlogn$ 级别的考虑。</p><p>考虑分治。在一段 $1-n$ 的区间中，把 $[(n+1)/2,n]$ 的先依次加一,这样整体就分成了不同两部分，在运用第一种操作整体加一。</p><p>具体细节看代码$merge$函数：</p><pre><code class="lang-c++">int n, a[N], c[N];PII b[N];vector&lt;array&lt;int, 2&gt;&gt; op;void merge(int l, int r, int val)//val：此时整个区间的值&#123;    if (b[r].f == val)        return;    int mid = l + r + 1 &gt;&gt; 1, now = val;    if (b[mid].f &gt; val)    &#123;        for (int i = mid; i &lt;= r; i++)        &#123;            op.pb(&#123;2, b[i].s&#125;);        &#125;        now++;    &#125;    while (now &lt; b[mid].f)//让整个右区间的值变成mid        op.pb(&#123;1, now&#125;), now++;    if (b[r].f &gt; now)        merge(mid, r, now);    merge(l, mid - 1, val);&#125;void solve()&#123;    cin &gt;&gt; n;    for (int i = 1; i &lt;= n; i++)    cin &gt;&gt; a[i], b[i] = &#123;a[i], i&#125;;    sort(b + 1, b + 1 + n);    merge(1, n, 0);    cout &lt;&lt; op.size() &lt;&lt; &quot;\n&quot;;    for (auto &amp;[x, y] : op)    cout &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; y &lt;&lt; &quot;\n&quot;;&#125;</code></pre><h2 id="F-见面礼"><a href="#F-见面礼" class="headerlink" title="F:见面礼"></a>F:见面礼</h2><h4 id="Description-1"><a href="#Description-1" class="headerlink" title="Description"></a>Description</h4><p>给定一个 n 个点 n 条边的无向图，你需要求有多少种选择图上的一个点 p 和一条边 (x,y) 的方案，使得删去 (x,y) 后图变成一棵树，且这棵树以 p 为根时每个节点的儿子个数均不超过 3。<strong>保证至少存在一种这样的方案。</strong></p><h4 id="Input-1"><a href="#Input-1" class="headerlink" title="Input"></a>Input</h4><p>输入的第一行一个整数 n（2≤n≤105） 表示节点数，接下来 n 行每行两个整数 x,y（1≤x,y≤n） 描述图上的一条边。保证图中没有重边自环。</p><h4 id="Output-1"><a href="#Output-1" class="headerlink" title="Output"></a>Output</h4><p>输出一行一个正整数表示答案。</p><h4 id="分析：-1"><a href="#分析：-1" class="headerlink" title="分析："></a>分析：</h4><p>队友写的，应该是个结论题。</p><p>粘一下官方题解：</p><p>由于保证存在一个方案，所以给出的图一定是一棵基环树。找到 基环树的环后，删去的边一定在环上。 枚举被删去的边（也就是环上的边），我们需要快速地确定选根 的方案数。 考虑一个点作为根的条件。注意到每个点的儿子个数不超过3的 充要条件是：根的度数不超过3，其余节点的度数不超过4。 于是维护每种度数的出现次数（注意到保证有解时，所有节点的 度数均不会超过5），删边时修改相邻的两个节点的度数。当不 存在度数为5的节点时，选根的方案数即为度数不超过3的节 点个数，否则不存在选根的方案。</p><pre><code class="lang-c++">int T, n, m;vector&lt;int&gt;v[N];int p[N], ff = 0, q[N], cnt = 0;bool st[N];void dfs(int u, int f)&#123;    for(int it : v[u])    &#123;        if(it == f) continue;        if(ff) return;        p[it] = u;        // cout &lt;&lt; it &lt;&lt; &#39;\n&#39;;        if(st[it])        &#123;            // cout &lt;&lt; &quot; ---&quot; &lt;&lt; it &lt;&lt; &#39;\n&#39;;            int x = it;            while(p[x] != it &amp;&amp; p[x] != 0)            &#123;                q[++ cnt] = p[x];                x = p[x];            &#125;            q[++ cnt] = p[x];            // for(int i = 1; i &lt;= cnt; i ++)            // &#123;            //     cout &lt;&lt; q[i] &lt;&lt;&quot; \n&quot;[i == cnt];            // &#125;            ff = 1;            return;        &#125;        st[it] = true;        dfs(it, u);        if(ff) return;    &#125;&#125;int num[N];void solve()&#123;    cin &gt;&gt; n;    for(int i = 1; i &lt;= n; i ++)    &#123;        int x, y;        cin &gt;&gt; x &gt;&gt; y;        v[x].push_back(y);        v[y].push_back(x);        num[x] ++;        num[y] ++;    &#125;    dfs(1, 0);    q[cnt + 1] = q[1];    int cnt1 = 0, cnt2 = 0;    for(int i = 1; i &lt;= n; i ++)    &#123;        if(num[i] == 5) cnt1 ++;        if(num[i] == 4) cnt2 ++;    &#125;    int ans = 0;    for(int i = 1; i &lt;= cnt; i ++)    &#123;        int t1 = q[i], t2 = q[i + 1];        int n1 = 0, n2 = 0;        if(num[t1] == 5) n1 ++, n2 --;        if(num[t1] == 4) n2 ++;        if(num[t2] == 5) n1 ++, n2 --;        if(num[t2] == 4) n2 ++;        if(cnt1 - n1 != 0) continue;        ans += n - (cnt2 - n2);    &#125;    cout &lt;&lt; ans &lt;&lt; &#39;\n&#39;;&#125;</code></pre><h2 id="G-相似基因序列问题"><a href="#G-相似基因序列问题" class="headerlink" title="G:相似基因序列问题"></a>G:相似基因序列问题</h2><p><strong>【题目描述】</strong></p><p>已知一棵包含了 N 个生物的系统进化树，这些生物的 DNA 序列对应的对齐至 M 个片段的序列可以用仅含小写字母的字符串表示为 s1,…,sN。在这棵系统进化树上，如果两个生物对应的序列最多只有 K 处对应位置上的片段不相同（即对应字母不同），就称这两个生物的亲缘关系相近。</p><p>现有 Q 个尚未确定亲缘关系的生物，对齐得到序列分别为 t1,…,tQ。为了确定这些生物在系统进化树上的位置，请对 Q 个生物分别求出，原树中有多少个生物与其亲缘关系相近。</p><h4 id="Input-2"><a href="#Input-2" class="headerlink" title="Input"></a>Input</h4><p>输入的第一行包含四个正整数 N,Q,M,K，分别表示系统进化树上的生物数量、待确定亲缘关系的生物数量、对齐后的序列长度和比较序列时容许的最大差异数。保证 1≤N,Q≤300，1≤M≤60,000，1≤K≤10。</p><p>接下来 N 行，每行输入一个长度恰好为 M，仅包含小写字母的字符串 si，表示系统进化树上的每个生物对应的模板序列。</p><p>接下来 Q 行，每行输入一个长度恰好为 M，仅包含小写字母的字符串 tj，表示待确定亲缘关系的每个生物对应的查询序列。</p><p>保证输入的两个字符串均仅包含小写字母。</p><h4 id="Output-2"><a href="#Output-2" class="headerlink" title="Output"></a>Output</h4><p>输出共 Q 行，其中第 j 行输出一个非负整数，表示在系统进化树上与第 j 个待确定的生物亲缘关系相近的生物数量。</p><p>分析：</p><p>队友写的二分+hash。</p><p>中途我怕被卡hash跟他们说写双hash，mle了，改完单hash又tle一发 ，二分提前break过的。</p><pre><code class="lang-c++">int q, k, T, n, m;string s[N], c[N];const int mod = 1e9 + 13, mod2 = 1e9 + 17;const int P = 131, P2 = 13331;int h[N][M], hc[N][M], p[M];// int h2[N][M], hc2[N][M], p2[M];int check(int l, int r, int t1, int t2)&#123;    int x1 = (hc[t1][r] - hc[t1][l - 1] * p[r - l + 1] % mod + mod) % mod;    int x2 = (h[t2][r] - h[t2][l - 1] * p[r - l + 1] % mod + mod) % mod;    // int y1 = (hc2[t1][r] - hc2[t1][l - 1] * p2[r - l + 1] % mod2 + mod2) % mod2;    // int y2 = (h2[t2][r] - h2[t2][l - 1] * p2[r - l + 1] % mod2 + mod2) % mod2;    if(x1 == x2) return true;    return false;&#125;void solve()&#123;    cin &gt;&gt; n &gt;&gt; q &gt;&gt; m &gt;&gt; k;    p[0] = 1;    // p2[0] = 1;    for(int i = 1; i &lt;= m; i ++)    &#123;        p[i] = p[i - 1] * P % mod;        // p2[i] = p2[i - 1] * P2 % mod2;    &#125;    for(int i = 1; i &lt;= n; i ++)    &#123;        cin &gt;&gt; s[i];        int z = s[i].size();        s[i] = &#39; &#39; + s[i];        for(int j = 1; j &lt;= z; j ++)        &#123;            h[i][j] = (h[i][j - 1] * P % mod + s[i][j]) % mod;            // h2[i][j] = (h2[i][j - 1] * P2 % mod2 + s[i][j]) % mod2;        &#125;    &#125;    for(int i = 1; i &lt;= q; i ++)    &#123;        cin &gt;&gt; c[i];        int z = c[i].size();        c[i] = &#39; &#39; + c[i];        for(int j = 1; j &lt;= z; j ++)        &#123;            hc[i][j] = (hc[i][j - 1] * P % mod + c[i][j]) % mod;            // hc2[i][j] = (hc2[i][j - 1] * P2 % mod2 + c[i][j]) % mod2;        &#125;        int ans = 0;        for(int j = 1; j &lt;= n; j ++)        &#123;            int lr = 1, cnt = 0;            while(lr &lt;= m)            &#123;                int l = lr, r = m;                while(l &lt; r)                &#123;                    int mid = l + r &gt;&gt; 1;                    if(check(l, mid, i, j)) l = mid + 1;                    else r = mid;                 &#125;                if(c[i][l] != s[j][l])                &#123;                    cnt ++;                &#125;                lr = l + 1;                if(cnt &gt; k) break;            &#125;            if(cnt &lt;= k) ans ++;        &#125;        cout &lt;&lt; ans &lt;&lt; &#39;\n&#39;;    &#125;&#125;</code></pre><h2 id="Description-2"><a href="#Description-2" class="headerlink" title="Description"></a>Description</h2><p><strong>【题目描述】</strong></p><p>出生于魔王家族的 Mary，从小便与同龄的普通人类有所不同。比如说，Mary 的头两侧长有一对犄角，可以捕捉到远处细微的变化；比如说，Mary 身上的魔力会吸引神秘的生物，这些友善的来客自在地游曳在魔王城中，将其点缀成了一座坐落于偏僻孤岛上的水族馆；再比如，Mary 有一棵与生俱来的有根树。</p><p>Mary 有棵有根树。</p><p>在 Mary 出生时，这棵有根树也一同降临在了世界上。照料好自己的有根树是魔王家族世世代代的传承，但让有根树生长的方法却因人而异。Mary 不知道如何让这棵只有一个结点的有根树生长，而她的父母也不得而知。虽然 Mary 的有根树从未生长，但是 Mary 像普通人类一样不断成长，她所能驾驭的魔力也随之越来越强。Mary 的成长获得了父母的认可，他们将魔王家族中象征着力量成熟的魔法——闪耀魔法传授给了 Mary。当 Mary 第一次成功施展了闪耀魔法时，她的有根树终于产生了变化：从原来的根结点上，长出了 M 个新的结点。原来，每当 Mary 施展一次闪耀魔法时，她的有根树都会有一个叶结点恰好长出 M 个<strong>可以区分的</strong>子结点。每次进行生长的叶结点是在所有尚未生长的叶结点中等概率随机产生的，而已经拥有 M 个子结点的非叶结点不会再次生长。</p><p>Mary 想知道：在她总共使用了 K 次闪耀魔法之后，她的有根树上各个结点的深度总和的期望。最初没有使用闪耀魔法时，只有一个结点的有根树的深度定义为 0。</p><h4 id="Input-3"><a href="#Input-3" class="headerlink" title="Input"></a>Input</h4><p>输入仅一行，包括两个由单个空格隔开的正整数 M，K，表示从一个结点上可以长出的子结点的数量，以及使用闪耀魔法的次数。保证 1≤M≤100，1≤K≤107。</p><h4 id="Output-3"><a href="#Output-3" class="headerlink" title="Output"></a>Output</h4><p>输出一个数，表示 Mary 的有根树的结点深度和的期望。假设期望深度和化为最简分式后的形式为 p/q（即其中 p,q 互质），请输出非负整数 x 使得 qx≡p(mod1,000,000,009)，且 0≤x&lt;1,000,000,009。可以证明，在本题数据范围下，x 存在且唯一。</p><h4 id="分析：-2"><a href="#分析：-2" class="headerlink" title="分析："></a>分析：</h4><p>设$f_1$表示叶子节点深度的全部期望，$f_2$表示非叶子节点深度的全部期望。</p><p>在进行一次闪耀魔法时：</p><p>全部叶子的节点数量:$sz_i=sz_{i-1}+m-1$</p><p>一个叶子节点的期望深度:d=$\frac{f_1}{sz_i}$</p><p>显然会有一个叶子节点变为非叶子节点：$f_2+=d$</p><p>新的叶子节点一定是上一次的叶子节点期望深度+1：$f_1+=(d+1)*m-d$</p><p>那么对于最终的答案就是$f_1+f_2$.</p><pre><code class="lang-c++">int f1[N],f2[N];int qmi(int a,int b)&#123;    int res=1;    while(b)&#123;        if(b&amp;1)res=res*a%P;        a=a*a%P;        b&gt;&gt;=1;    &#125;    return res;&#125;void solve()&#123;    int m,k;cin&gt;&gt;m&gt;&gt;k;    for(int i=1,sum=1;i&lt;=k;i++,sum+=m-1,sum%=P)&#123;        int ver=f1[i-1]*qmi(sum,P-2)%P;        f2[i]=f2[i-1]+ver;        f2[i]%=P;        f1[i]=(f1[i-1]+(ver+1)*m%P-ver+P)%P;    &#125;    cout&lt;&lt;(f1[k]+f2[k])%P&lt;&lt;&quot;\n&quot;;&#125;</code></pre><h2 id="I：不定方程"><a href="#I：不定方程" class="headerlink" title="I：不定方程"></a>I：不定方程</h2><h4 id="Description-3"><a href="#Description-3" class="headerlink" title="Description"></a>Description</h4><p>给定正整数 n,k，求不定方程 $a^k−b^k=n$ 的正整数解数量。</p><h4 id="Input-4"><a href="#Input-4" class="headerlink" title="Input"></a>Input</h4><p>输入第一行一个整数 T（1≤T≤20） 表示询问数量。之后 T 行，每一行两个整数 n,k 表示一次询问。保证 1≤n≤1018，3≤k≤64。</p><h4 id="Output-4"><a href="#Output-4" class="headerlink" title="Output"></a>Output</h4><p>对于每一组询问，输出一行一个非负整数表示答案。</p><h4 id="分析：-3"><a href="#分析：-3" class="headerlink" title="分析："></a>分析：</h4><h5 id="正解："><a href="#正解：" class="headerlink" title="正解："></a>正解：</h5><h5 id="偏解："><a href="#偏解：" class="headerlink" title="偏解："></a>偏解：</h5><p>$a^k-b^k=(a-b)(a^{k-1}+a^{k-2}b+…b^{k-1}=n$</p><p>设$c=(a-b),a=b+c$ 带入原式：$(b+c)^k-b^k$</p><p>首先通过第一行可以看出（a-b）是n的质因子，其次$(b+c)^k-b^k$ 显然单调递增</p><p>所以我们可以枚举n的因子，然后二分答案寻找b</p><p>由于n很大我们可以用$Pollard-Rho$在$n^{\frac{1}{4}}$枚举单个因子 ，带回除掉再找其他的因子。</p>]]></content:encoded>
      
      
      
      
      <comments>https://lifexoryoung.cn/2024/10/18/2024CCPC%E6%B7%B1%E5%9C%B3%E7%AB%99%E7%BB%84%E9%98%9F%E8%B5%9B%E9%A2%98%E8%A7%A3/#disqus_thread</comments>
      
    </item>
    
    <item>
      <title>补题</title>
      <link>https://lifexoryoung.cn/2024/09/16/%E8%A1%A5%E9%A2%98/</link>
      <guid>https://lifexoryoung.cn/2024/09/16/%E8%A1%A5%E9%A2%98/</guid>
      <pubDate>Mon, 16 Sep 2024 08:24:34 GMT</pubDate>
      
        
        
      <description>&lt;p&gt;&lt;a href=&quot;https://www.luogu.com.cn/problem/P2508&quot;&gt;P2508 [HAOI2008] 圆上的整点 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;分析：&lt;/p&gt;
&lt;p&gt;$y^2=r^2-x</description>
        
      
      
      
      <content:encoded><![CDATA[<p><a href="https://www.luogu.com.cn/problem/P2508">P2508 [HAOI2008] 圆上的整点 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)</a></p><p>分析：</p><p>$y^2=r^2-x^2=(r-x)(r+x) $</p><p>设$d=gcd(r-x,r+x),r-x=u<em>d,r+x=v</em>d$</p><p>则原式变为：$y^2=d^2<em>u</em>v$</p><p>则可以列出两个等式：</p><p>$x=\frac{v-u}{2}d,2r=({u+v})d$</p><p>枚举2r的约数d并枚举u可以在$o(\sqrt{r}+\sum\frac{2r}{d})$解决该问题，显然时间复杂度不能接受</p><p>注意到u,v互质并且等式左边为平方数则u,v为平方数：</p><p>不妨设$u=s^2,v=t^2$</p><p>则等式变为：$x=\frac{t^2-s^2}{2}d,2r=(s^2+t^2)d$</p><p>此时枚举2r的约束d并枚举s可以在$o(\sqrt{r}+\sum \sqrt\frac{2r}{d})$求解</p><p>r数的约数可以粗略估计为$2^{10}$最大不会超过r，所以最大时间复杂度为$o(\sqrt{r}<em>2^{10})$ 约为$3</em>10^7$</p><p>(实际远比这个小)</p><pre><code class="lang-c++">int ans,R;void get(int d,int r)&#123;    // cout&lt;&lt;d&lt;&lt;&quot; &quot;&lt;&lt;r&lt;&lt;&quot;\n&quot;;    for(int i=1;i&lt;=r/i;i++)&#123;        int s=i,t=sqrt(r-i*i);        if(s*s+t*t!=r||__gcd(s,t)!=1)continue;        int x=(t*t-s*s)/2*d,y=d*s*t;        // cout&lt;&lt;x&lt;&lt;&quot; &quot;&lt;&lt;y&lt;&lt;&quot;\n&quot;;        if(x&gt;0&amp;&amp;y&gt;0&amp;&amp;x*x+y*y==(R/2)*(R/2))ans+=2;    &#125;&#125;void solve()&#123;    int r;cin&gt;&gt;r;    r&lt;&lt;=1;    R=r;    for(int i=1;i&lt;=r/i;i++)&#123;        if(r%i==0)get(i,r/i);        if(r%i==0&amp;&amp;i*i!=r)get(r/i,r/(r/i));    &#125;    cout&lt;&lt;(ans+1)*4&lt;&lt;&quot;\n&quot;;&#125;</code></pre>]]></content:encoded>
      
      
      
      
      <comments>https://lifexoryoung.cn/2024/09/16/%E8%A1%A5%E9%A2%98/#disqus_thread</comments>
      
    </item>
    
    <item>
      <title>数位DP</title>
      <link>https://lifexoryoung.cn/2024/09/13/%E6%95%B0%E4%BD%8DDP/</link>
      <guid>https://lifexoryoung.cn/2024/09/13/%E6%95%B0%E4%BD%8DDP/</guid>
      <pubDate>Fri, 13 Sep 2024 13:10:38 GMT</pubDate>
      
        
        
      <description>&lt;h1 id=&quot;ZJOI2010-数字计数&quot;&gt;&lt;a href=&quot;#ZJOI2010-数字计数&quot; class=&quot;headerlink&quot; title=&quot;[ZJOI2010] 数字计数&quot;&gt;&lt;/a&gt;[ZJOI2010] 数字计数&lt;/h1&gt;&lt;h2 id=&quot;题目描述&quot;&gt;&lt;a href=&quot;#题</description>
        
      
      
      
      <content:encoded><![CDATA[<h1 id="ZJOI2010-数字计数"><a href="#ZJOI2010-数字计数" class="headerlink" title="[ZJOI2010] 数字计数"></a>[ZJOI2010] 数字计数</h1><h2 id="题目描述"><a href="#题目描述" class="headerlink" title="题目描述"></a>题目描述</h2><p>给定两个正整数 $a$ 和 $b$，求在 $[a,b]$ 中的所有整数中，每个数码(digit)各出现了多少次。</p><h2 id="输入格式"><a href="#输入格式" class="headerlink" title="输入格式"></a>输入格式</h2><p>仅包含一行两个整数 $a,b$，含义如上所述。</p><h2 id="输出格式"><a href="#输出格式" class="headerlink" title="输出格式"></a>输出格式</h2><p>包含一行十个整数，分别表示 $0\sim 9$ 在 $[a,b]$ 中出现了多少次。</p><h2 id="样例-1"><a href="#样例-1" class="headerlink" title="样例 #1"></a>样例 #1</h2><h3 id="样例输入-1"><a href="#样例输入-1" class="headerlink" title="样例输入 #1"></a>样例输入 #1</h3><pre><code>1 99</code></pre><h3 id="样例输出-1"><a href="#样例输出-1" class="headerlink" title="样例输出 #1"></a>样例输出 #1</h3><pre><code>9 20 20 20 20 20 20 20 20 20</code></pre><h2 id="提示"><a href="#提示" class="headerlink" title="提示"></a>提示</h2><h4 id="数据规模与约定"><a href="#数据规模与约定" class="headerlink" title="数据规模与约定"></a>数据规模与约定</h4><ul><li>对于 $30\%$ 的数据，保证 $a\le b\le10^6$；</li><li>对于 $100\%$ 的数据，保证 $1\le a\le b\le 10^{12}$。</li></ul><p>分析：</p><p>设dp_i表示在不考虑前导零，满i位（&lt;10^i）时一种数出现了多少次</p><p>对于前i位：</p><p>1.前导零合法时，0~9的数量都相同：对于dp_i=dp_{i-1}*10</p>]]></content:encoded>
      
      
      
      
      <comments>https://lifexoryoung.cn/2024/09/13/%E6%95%B0%E4%BD%8DDP/#disqus_thread</comments>
      
    </item>
    
    <item>
      <title>2024“钉耙编程”中国大学生算法设计超级联赛(4)</title>
      <link>https://lifexoryoung.cn/2024/07/29/2024%E2%80%9C%E9%92%89%E8%80%99%E7%BC%96%E7%A8%8B%E2%80%9D%E4%B8%AD%E5%9B%BD%E5%A4%A7%E5%AD%A6%E7%94%9F%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1%E8%B6%85%E7%BA%A7%E8%81%94%E8%B5%9B-4/</link>
      <guid>https://lifexoryoung.cn/2024/07/29/2024%E2%80%9C%E9%92%89%E8%80%99%E7%BC%96%E7%A8%8B%E2%80%9D%E4%B8%AD%E5%9B%BD%E5%A4%A7%E5%AD%A6%E7%94%9F%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1%E8%B6%85%E7%BA%A7%E8%81%94%E8%B5%9B-4/</guid>
      <pubDate>Mon, 29 Jul 2024 12:17:44 GMT</pubDate>
      
      <description>&lt;h4 id=&quot;序列更新&quot;&gt;&lt;a href=&quot;#序列更新&quot; class=&quot;headerlink&quot; title=&quot;序列更新&quot;&gt;&lt;/a&gt;序列更新&lt;/h4&gt;&lt;p&gt;给定两个长度为n 的序列$ 𝑎_0,𝑎_1,…,𝑎_{𝑛−1}$ 和 $𝑏_0,𝑏_1,…,𝑏_{𝑛−1}$&lt;/p&gt;
&lt;p&gt;你需要依次执行q次操作，每次操作将会给出一个整数$k(0≤𝑘&amp;lt;𝑛)$，对于每个$ 𝑖 (0≤𝑖&amp;lt;𝑛)$，你需要将 $𝑎𝑖$ 更新为 $max⁡(𝑎_𝑖,𝑏_{𝑖+𝑘}&#92; mod&#92; 𝑛)。$为了证明你确实维护了a序列，请在每次操作之后输出 $&#92;sum_{i=0}^{i&amp;lt;n}a_i $的值。&lt;/p&gt;</description>
      
      
      
      <content:encoded><![CDATA[<h4 id="序列更新"><a href="#序列更新" class="headerlink" title="序列更新"></a>序列更新</h4><p>给定两个长度为n 的序列$ 𝑎_0,𝑎_1,…,𝑎_{𝑛−1}$ 和 $𝑏_0,𝑏_1,…,𝑏_{𝑛−1}$</p><p>你需要依次执行q次操作，每次操作将会给出一个整数$k(0≤𝑘&lt;𝑛)$，对于每个$ 𝑖 (0≤𝑖&lt;𝑛)$，你需要将 $𝑎𝑖$ 更新为 $max⁡(𝑎_𝑖,𝑏_{𝑖+𝑘}\ mod\ 𝑛)。$为了证明你确实维护了a序列，请在每次操作之后输出 $\sum_{i=0}^{i&lt;n}a_i $的值。</p><span id="more"></span><h4 id="Input"><a href="#Input" class="headerlink" title="$Input$"></a>$Input$</h4><p>第一行包含一个正整数 $T (1≤𝑇≤2)$，表示测试数据的组数。</p><p>每组数据第一行包含两个正整数$ 𝑛,𝑞 (1≤𝑛,𝑞≤250,000)$，分别表示序列的长度以及操作的次数。</p><p>第二行包含 $𝑛 $个正整数 $𝑎_0,𝑎_1,…,𝑎_{𝑛−1} (1≤𝑎𝑖≤10^9)$。</p><p>第三行包含 $𝑛$ 个正整数 $𝑏0,𝑏1,…,𝑏𝑛−1(1≤𝑏𝑖≤10^9)。$</p><p>接下来 𝑞行，每行一个整数 𝑘 (0≤𝑘&lt;𝑛)，依次描述每次操作。</p><p>输入数据保证每个 𝑎𝑖,𝑏𝑖 都是在 $[1,10^9]$均匀随机生成得到（样例除外），且每个 <em>k</em> 都是在 $[0,𝑛)$均匀随机生成得到（样例除外）。</p><h4 id="Output"><a href="#Output" class="headerlink" title="$Output$"></a>$Output$</h4><p>对于每组数据输出 𝑞 行，其中第 𝑖 行输出一个整数，即在第 𝑖 次操作完毕之后 $\sum_{i=0}^{i&lt;n}a_i$的值。</p><p>$Sample Input$</p><p>1 5 5 1 5 3 6 8 2 5 4 7 3 3 2 4 1 0</p><p>$Sample Output$</p><p>29 31 33 35 36</p><h4 id="分析"><a href="#分析" class="headerlink" title="$分析$:"></a>$分析$:</h4><p>常规考虑基本都是$o(n^2)$无解。唯一指向性的线索就是$a_i$只会单调递增以及$a_i,b_i,k$都是均匀随机生成。</p><p>考虑在$b_i$之间设置一个阙值$S$：</p><p>当$a_i \le S$,对于每个$k$都依次去用$b_{(i+k)\%n}$尝试更新$a_i$，直到大于$S$。</p><p>当$a_i &gt;S$,则存起来，后用$b_i$去更新$a_{(i-k)\%k}$</p><p>对于第二种期望次数为设为x次（即有x个数大于S）</p><p>对于第一种：即为连续$i$次每个数都不超过$S$的概率为$（1-\frac{x}{n}）$让$a_i&gt;x$的期望次数$\frac{x}{n}\sum_{i&gt;=0}^{无穷次}(i+1)(1- \frac{x}{n})^i\approx\frac{n}{x}$</p><h4 id="证明："><a href="#证明：" class="headerlink" title="$证明：$"></a>$证明：$</h4><p>$设p=\frac{x}{n}$</p><p>原式为$ans=p<em>\sum_{i&gt;=0}^{\infty}(i+1)(i-p)^i= p</em>(1<em>(1-p)^0+2</em>(1-p)^1+3<em>(1-p)^2….+(i+1)</em>(1-p)^i)$</p><p>上式两边同时$×(1-p)$得：$ans<em>(1-p)=p</em>(1<em>(1-p)^1+2</em>(1-p)^2+3<em>(1-p)^3….+(i+1)</em>(1-p)^{i+1})$</p><p>$ans<em>(1-p)=p</em>((1-p)^1+(1-p)^2+(1-p)^3….+(1-p)^{i+1})-正无穷小$</p><p>正无穷小$\approx0$,原式由等比数列求和化简可得：$ans=\frac{1}{1-p}=\frac{n}{x}+1$,其中1可以忽略不计只需要保证$x&gt;=1$即可</p><p>总时间复杂度为$o(n*x+\frac{n^2}{x})$</p><p>当$n*x=\frac{n^2}{x}$时即$x=\sqrt{n}$时间复杂度最优为$o(n\sqrt{n})$</p><pre><code class="lang-cpp">#include&lt;bits/stdc++.h&gt;using namespace std;#define ll long long#define pb push_back#define int long long#define PII pair&lt;int, int&gt;#define PI acos(-1)#define s second#define f first#define Bint __int128#define all(x) x.begin(),x.end()#define isdigit(x) ((x) &gt;= &#39;0&#39; &amp;&amp; (x) &lt;= &#39;9&#39;)#define double long double#define ULL unsigned long longconst int N = 2e5 + 7, P = 998244353;const int M = 1e6 + 7, inf = 0x3f3f3f3f3f3f3f3f;const double eps = 1e-6;int n,q,a[N],b[N],c[N],A[N],B[N],ca,cb,sum;inline void fix(int&amp;x)&#123;  while(x&lt;=0)x+=n;  while(x&gt;n)x-=n;&#125;inline void modify(int x,int y)&#123;    fix(x);    fix(y);    if(a[x]&gt;=b[y])return ;    sum+=b[y]-a[x];    a[x]=b[y];&#125;void solve()&#123;    ca=0,cb=0;    cin&gt;&gt;n&gt;&gt;q;    sum=0;    for(int i=1;i&lt;=n;i++)cin&gt;&gt;a[i];    for(int i=1;i&lt;=n;i++)cin&gt;&gt;b[i],c[i]=b[i];    int s=sqrt(n);    s=max(s,(int)1);    sort(c+1,c+1+n);    for(int i=1;i&lt;=n;i++)&#123;        sum+=a[i];        if(a[i]&lt;=s)A[ca++]=i;        if(b[i]&gt;s)B[cb++]=i;    &#125;    while(q--)&#123;        int k;cin&gt;&gt;k;        for(int i=0;i&lt;ca;)&#123;            modify(A[i],A[i]+k);            if(a[A[i]]&gt;s)swap(A[i],A[--ca]);else i++;        &#125;        for(int i=0;i&lt;cb;i++)&#123;            modify(B[i]-k,B[i]);        &#125;    &#125;    return ;&#125;signed main()&#123;    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);    int T=1;    cin&gt;&gt;T;    while(T--)&#123;        solve();    &#125;    return 0;&#125;</code></pre><h4 id="最优-K-子段"><a href="#最优-K-子段" class="headerlink" title="最优 K 子段"></a>最优 K 子段</h4><h4 id="分析："><a href="#分析：" class="headerlink" title="分析："></a>分析：</h4><p>首先对最小值二分答案。那么在$check$中贪心维护最小值$&gt;=mid$的最多子段数量。</p><p>从左端点开始枚举，通过维护一个前缀$set$去保证以位置$i$结尾的子段可以$pre[i]-set.pre&gt;=x。$</p><p>那么对于每一个$i$暴力枚举$set$中的元素满足$i-set.pos$为质数的时间复杂度为多少？</p><p>因为起初数组元素是均匀分布，那么其$x-前缀$也满足均匀分布，那么其位置$set.pos$也满足均匀分布</p><p>因为$1-n$的质数个数$\approx\frac{n}{ln}$,为质数概率$\frac{1}{ln}$，期望为$ln\approx logn$</p><p>$所以单次枚举时间复杂度O(logn)，总时间复杂度O(log(n<em>log+n</em>log))\approx O(nlog^2)$</p><pre><code class="lang-c++">#include&lt;bits/stdc++.h&gt;using namespace std;#define ll long long#define pb push_back#define int long long#define PII pair&lt;int, int&gt;#define PI acos(-1)#define s second#define f first#define Bint __int128#define all(x) x.begin(),x.end()#define isdigit(x) ((x) &gt;= &#39;0&#39; &amp;&amp; (x) &lt;= &#39;9&#39;)#define double long double#define ULL unsigned long longconst int N = 2e5 + 7, P = 998244353;const int M = 1e6 + 7, inf = 0x3f3f3f3f3f3f3f3f;const double eps = 1e-6;int n,a[N],k,pre[N];int primes[1000009],cnt;bool st[1000009];set&lt;PII&gt;b;void get_primes(int n)&#123;    st[1]=1;    for (int i = 2; i &lt;= n; i ++ )    &#123;        if (!st[i]) primes[cnt ++ ] = i;        for (int j = 0; primes[j] &lt;= n / i; j ++ )        &#123;            st[primes[j] * i] = true;            if (i % primes[j] == 0) break;        &#125;    &#125;&#125;bool check(int x)&#123;    b.clear();    b.insert(PII&#123;0,0&#125;);    int res=0;    for(int i=1;i&lt;=n;i++)&#123;        int s=pre[i];        if(pre[i]-b.begin()-&gt;f&gt;=x)&#123;            bool f=0;            for(auto &amp;[p,pos]:b)&#123;                if(s-p&gt;=x&amp;&amp;!st[i-pos])&#123;                    f=1;                    break;                &#125;                else if(s-p&lt;x)break;            &#125;            if(f)&#123;            res++;            b.clear();            if(res==k)return 1;            &#125;        &#125;        b.insert(PII&#123;pre[i],i&#125;);    &#125;    return 0;&#125;void solve()&#123;    cin&gt;&gt;n&gt;&gt;k;    for(int i=1;i&lt;=n;i++)cin&gt;&gt;a[i],pre[i]=a[i]+pre[i-1];    int l=0,r=0;    for(int i=1;i&lt;=n;i++)    if(a[i]&gt;=0)r+=a[i];    else l+=a[i];    while(l&lt;r)&#123;        int mid=l+r+1&gt;&gt;1;        if(check(mid))l=mid;        else r=mid-1;    &#125;    if(check(l))    cout&lt;&lt;l&lt;&lt;&quot;\n&quot;;    else cout&lt;&lt;&quot;impossible\n&quot;;&#125;signed main()&#123;    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);    int T=1;    cin&gt;&gt;T;    while(T--)&#123;        solve();    &#125;    return 0;&#125;</code></pre>]]></content:encoded>
      
      
      <category domain="https://lifexoryoung.cn/categories/%E6%AF%94%E8%B5%9B/">比赛</category>
      
      <category domain="https://lifexoryoung.cn/categories/%E6%AF%94%E8%B5%9B/%E6%9D%AD%E7%94%B5%E5%A4%9A%E6%A0%A1/">杭电多校</category>
      
      
      <category domain="https://lifexoryoung.cn/tags/%E6%9C%9F%E6%9C%9B/">期望</category>
      
      <category domain="https://lifexoryoung.cn/tags/%E6%A6%82%E7%8E%87%E8%AE%BA/">概率论</category>
      
      <category domain="https://lifexoryoung.cn/tags/%E6%A0%B9%E5%8F%B7%E6%80%9D%E6%83%B3/">根号思想</category>
      
      
      <comments>https://lifexoryoung.cn/2024/07/29/2024%E2%80%9C%E9%92%89%E8%80%99%E7%BC%96%E7%A8%8B%E2%80%9D%E4%B8%AD%E5%9B%BD%E5%A4%A7%E5%AD%A6%E7%94%9F%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1%E8%B6%85%E7%BA%A7%E8%81%94%E8%B5%9B-4/#disqus_thread</comments>
      
    </item>
    
    <item>
      <title>2024暑假集训第一周总结</title>
      <link>https://lifexoryoung.cn/2024/07/21/2024%E6%9A%91%E5%81%87%E9%9B%86%E8%AE%AD%E7%AC%AC%E4%B8%80%E5%91%A8%E6%80%BB%E7%BB%93/</link>
      <guid>https://lifexoryoung.cn/2024/07/21/2024%E6%9A%91%E5%81%87%E9%9B%86%E8%AE%AD%E7%AC%AC%E4%B8%80%E5%91%A8%E6%80%BB%E7%BB%93/</guid>
      <pubDate>Sun, 21 Jul 2024 09:52:39 GMT</pubDate>
      
      <description>&lt;p&gt;&lt;em&gt;迟来的第一周总结….&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;第一周一共四场比赛：总的来说还有很多东西没学，或者学的不深，个人感觉八月之前应该在不停的学新东西了，八月之后得对算法加深一些理解和掌握。比赛得时候，签到和能出得思维大家都一样，后期就看谁知识点学过或者掌握的更深了…&lt;/p&gt;</description>
      
      
      
      <content:encoded><![CDATA[<p><em>迟来的第一周总结….</em></p><p>第一周一共四场比赛：总的来说还有很多东西没学，或者学的不深，个人感觉八月之前应该在不停的学新东西了，八月之后得对算法加深一些理解和掌握。比赛得时候，签到和能出得思维大家都一样，后期就看谁知识点学过或者掌握的更深了…</p><span id="more"></span><p>牛客多校一：</p><p>这一场补了三个题</p><hr><p><a href="https://ac.nowcoder.com/acm/contest/81596/A">A-A Bit Common_2024牛客暑期多校训练营1 (nowcoder.com)</a></p><p>$题意是给你n(n\le5000),m(m\le5000),q(q\le10^9)三个数,求从[0,2^m)任取数凑成长度为n的序列，并且该序列中存在一个子$</p><p>$序列AND值为1，求总共的方案数并对\ q \  取模。$</p><p>$分析：$</p><p>$n,m都是5000，显然时间复杂度在o(n^2)以内，所以我们可以考虑枚举子序列的个数$</p><p>$假设子序列为k个 那么有c(n,k)种序列位置可能$.</p><p>$一个数AND为1 只能为1$</p><p>$多个数AND值为1，那么他们的2进制位最低位一定为1，其他位一定都不同时为1  $</p><p>$剩下的n-k个就随便选了 .$</p><p>$总结一下就得出一个公式：$</p><p>$\sum_{k=2}^{n} C(n,k)(2^k-1)^{m-1}2^{(m-1)(n-k)}$</p><p>$组合数预处理用递推式o(n^2)，枚举序列计算答案为o(nlogm),总时间复杂度为o(n^2)$</p><p>总结：题不难，也没用到的什么难的知识点 还是组合数论推式子类题刷的少 </p><hr><p><a href="https://ac.nowcoder.com/acm/contest/81596/B">B-A Bit More Common_2024牛客暑期多校训练营1 (nowcoder.com)</a></p><p>题意和范围跟上面一样，区别是找到序列中存在两个子序列AND值为1方案数</p><p>分析：</p>]]></content:encoded>
      
      
      
      
      <comments>https://lifexoryoung.cn/2024/07/21/2024%E6%9A%91%E5%81%87%E9%9B%86%E8%AE%AD%E7%AC%AC%E4%B8%80%E5%91%A8%E6%80%BB%E7%BB%93/#disqus_thread</comments>
      
    </item>
    
    <item>
      <title>费马小定理&amp;欧拉定理&amp;扩展欧拉定理</title>
      <link>https://lifexoryoung.cn/2024/06/11/%E8%B4%B9%E9%A9%AC%E5%B0%8F%E5%AE%9A%E7%90%86-%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86-%E6%89%A9%E5%B1%95%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86/</link>
      <guid>https://lifexoryoung.cn/2024/06/11/%E8%B4%B9%E9%A9%AC%E5%B0%8F%E5%AE%9A%E7%90%86-%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86-%E6%89%A9%E5%B1%95%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86/</guid>
      <pubDate>Tue, 11 Jun 2024 13:29:33 GMT</pubDate>
      
        
        
      <description>&lt;p&gt;sdf dsf&lt;/p&gt;
</description>
        
      
      
      
      <content:encoded><![CDATA[<p>sdf dsf</p>]]></content:encoded>
      
      
      <category domain="https://lifexoryoung.cn/categories/%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86/">欧拉定理</category>
      
      <category domain="https://lifexoryoung.cn/categories/%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86/%E6%89%A9%E5%B1%95%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86/">扩展欧拉定理</category>
      
      <category domain="https://lifexoryoung.cn/categories/%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86/%E6%89%A9%E5%B1%95%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86/%E8%B4%B9%E9%A9%AC%E5%B0%8F%E5%AE%9A%E7%90%86/">费马小定理</category>
      
      
      <category domain="https://lifexoryoung.cn/tags/%E7%AC%94%E8%AE%B0/">笔记</category>
      
      
      <comments>https://lifexoryoung.cn/2024/06/11/%E8%B4%B9%E9%A9%AC%E5%B0%8F%E5%AE%9A%E7%90%86-%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86-%E6%89%A9%E5%B1%95%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86/#disqus_thread</comments>
      
    </item>
    
    <item>
      <title>强连通分量(scc缩点/tarjan)</title>
      <link>https://lifexoryoung.cn/2024/06/10/%E5%BC%BA%E8%BF%9E%E9%80%9A%E5%88%86%E9%87%8F-scc%E7%BC%A9%E7%82%B9-tarjan/</link>
      <guid>https://lifexoryoung.cn/2024/06/10/%E5%BC%BA%E8%BF%9E%E9%80%9A%E5%88%86%E9%87%8F-scc%E7%BC%A9%E7%82%B9-tarjan/</guid>
      <pubDate>Mon, 10 Jun 2024 11:46:24 GMT</pubDate>
      
      <description>&lt;p&gt;学习了一下强连通分量，整理一下：&lt;/p&gt;</description>
      
      
      
      <content:encoded><![CDATA[<p>学习了一下强连通分量，整理一下：</p><span id="more"></span><p>强连通分量的概念：任意两点之间能相互到达。</p><p>缩点简单来讲就是缩环成点，把强连通分量用一个点来维护，形成$DAG$有向无环图。</p><p>缩点方式有三种这里只说一下$tarjan$。</p><h3 id="tarjan-求-SCC-缩点：时间复杂度-O-n-m"><a href="#tarjan-求-SCC-缩点：时间复杂度-O-n-m" class="headerlink" title="$tarjan$求$SCC$缩点：时间复杂度$O(n+m)$"></a>$tarjan$求$SCC$缩点：时间复杂度$O(n+m)$</h3><p>单纯判断是否有环一般可以用$dfs$，那么在搜索过程中我们对点只有三种情况：</p><p>1.该点没有搜索过。</p><p>2.该点有搜索过，但是不是我们上一个遍历的点的祖宗节点。</p><p>3.该点有搜索过，是我们上一个遍历节点的祖宗节点。</p><p>下图描述了三种情况：黑色边为$1$，绿色边为$2$，蓝色边为$3$。</p><p>显然，只有第三种边能成环，成环的这些为强连通分量，其他的单独一个点作为强连通分量（自己本身就能到达自己），所以上图的强连通分量为（{1}，{2，3}，{4}，{5}）四个。</p><p>但是实际情况可能有很多个环嵌套，所以我们不能判断当前为环后，直接进行缩点，应该所有该子节点环判断完后，一块缩点。</p><p>为了解决这种问题，我们引入一个 $dfn$（时间戳）来记录我们第一次到达每个节点的顺序，一个 $low$（当前节点所接触到的最早的时间戳节点，初始为当前节点的 $dfn$ 值），在回溯的过程中对当前节点$low$与其子节点取$min$值来实现维护最大强连通分量集合，一个栈存我们 $dfs$ 过程的节点。</p><p>因为 $dfn==low$ 的时候说明此节点为一个强连通分量的最早结点，那么我们可以开始从栈头开始 $pop$，直到栈头等于当前节点，那么取出的节点即为我们所维护的一个强连通分量集合。</p><p>具体细节可以看代码：</p><pre><code class="lang-c++">int dfn[N],low[N],cnt,sz[N],scc[N],sc;stack&lt;int&gt;st;vector&lt;int&gt;e[N];bool vis[N];void tarjan(int u)&#123;    dfn[u]=low[u]=++cnt;    st.push(u),vis[u]=true;    for(auto &amp;to:e[u])&#123;        if(!dfn[to])&#123;            tarjan(to);            low[u]=min(low[u],low[to]);        &#125;        else if(vis[to])&#123;            low[u]=min(low[u],dfn[to]);        &#125;    &#125;    if(dfn[u]==low[u])&#123;        sc++;        while(st.top()!=u)&#123;            sz[sc]+=w[st.top()];            scc[st.top()]=sc;            vis[st.top()]=0;            st.pop();        &#125;        sz[sc]+=w[st.top()];        scc[st.top()]=sc;        vis[st.top()]=0;        st.pop();    &#125;&#125;</code></pre><h3 id="例题：P3387-【模板】缩点-洛谷-计算机科学教育新生态-luogu-com-cn"><a href="#例题：P3387-【模板】缩点-洛谷-计算机科学教育新生态-luogu-com-cn" class="headerlink" title="例题：P3387 【模板】缩点 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)"></a>例题：<a href="https://www.luogu.com.cn/problem/P3387">P3387 【模板】缩点 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)</a></h3><h4 id="题目描述"><a href="#题目描述" class="headerlink" title="题目描述"></a>题目描述</h4><p>给定一个 $n$ 个点 $m$ 条边有向图，每个点有一个权值，求一条路径，使路径经过的点权值之和最大。你只需要求出这个权值和。</p><p>允许多次经过一条边或者一个点，但是，重复经过的点，权值只计算一次。</p><h4 id="输入格式"><a href="#输入格式" class="headerlink" title="输入格式"></a>输入格式</h4><p>第一行两个正整数 $n,m$</p><p>第二行 $n$ 个整数，其中第 $i$ 个数 $a_i$ 表示点 $i$ 的点权。</p><p>第三至 $m+2$ 行，每行两个整数 $u,v$，表示一条 $u\rightarrow v$ 的有向边。</p><h4 id="输出格式"><a href="#输出格式" class="headerlink" title="输出格式"></a>输出格式</h4><p>共一行，最大的点权之和。</p><h4 id="样例-1"><a href="#样例-1" class="headerlink" title="样例 #1"></a>样例 #1</h4><h4 id="样例输入-1"><a href="#样例输入-1" class="headerlink" title="样例输入 #1"></a>样例输入 #1</h4><pre><code>2 21 11 22 1</code></pre><h4 id="样例输出-1"><a href="#样例输出-1" class="headerlink" title="样例输出 #1"></a>样例输出 #1</h4><pre><code>2</code></pre><h4 id="提示"><a href="#提示" class="headerlink" title="提示"></a>提示</h4><p>对于 $100\%$ 的数据，$1\le n \le 10^4$，$1\le m \le 10^5$，$0\le a_i\le 10^3$。</p><p>思路：</p><p>因为是有向图，所以可能存在有环的情况，因为每个点可以走多次，所以只要是路径上有环，我们全部取掉为最优。所以直接用$scc$缩点，重新建图，把图变为有向无环图$（DAG）$，新缩成的点的权值为全部点的点权和。那么该题就变成了，给你一个$DAG$，和每个点的点权，求点权最长路径。直接在新图的拓扑序中dp维护权值$max$即可。</p><pre><code class="lang-c++">int dfn[N],low[N],cnt,sz[N],scc[N],sc,d[N],dp[N],ans,w[N];stack&lt;int&gt;st;vector&lt;int&gt;e[N],ex[N];bool vis[N];queue&lt;int&gt;q;void tarjan(int u)&#123;    dfn[u]=low[u]=++cnt;    st.push(u),vis[u]=true;    for(auto &amp;to:e[u])&#123;        if(!dfn[to])&#123;            tarjan(to);            low[u]=min(low[u],low[to]);        &#125;        else if(vis[to])&#123;            low[u]=min(low[u],dfn[to]);        &#125;    &#125;    if(dfn[u]==low[u])&#123;        sc++;        while(st.top()!=u)&#123;            sz[sc]+=w[st.top()];            scc[st.top()]=sc;            vis[st.top()]=0;            st.pop();        &#125;        sz[sc]+=w[st.top()];        scc[st.top()]=sc;        vis[st.top()]=0;        st.pop();    &#125;&#125;void topu()&#123;    for(int i=1;i&lt;=sc;i++)if(!d[i])q.push(i),ans=max(ans,(dp[i]=sz[i]));    while(q.size())&#123;        int ver=q.front();        q.pop();        for(auto &amp;to:ex[ver])&#123;            d[to]--;            dp[to]=max(dp[to],dp[ver]+sz[to]);            ans=max(ans,dp[to]);            if(!d[to])q.push(to);        &#125;    &#125;&#125;void solve()&#123;    int n,m;cin&gt;&gt;n&gt;&gt;m;    for(int i=1;i&lt;=n;i++)cin&gt;&gt;w[i];    for(int i=1;i&lt;=m;i++)&#123;        int u,v;cin&gt;&gt;u&gt;&gt;v;        e[u].pb(v);    &#125;    for(int i=1;i&lt;=n;i++)&#123;        if(!dfn[i])tarjan(i);    &#125;    for(int i=1;i&lt;=n;i++)&#123;        int u=scc[i];        for(auto &amp;to:e[i])&#123;            int v=scc[to];            if(u==v)continue;            ex[u].pb(v);            d[v]++;        &#125;    &#125;    topu();    cout&lt;&lt;ans&lt;&lt;&quot;\n&quot;;&#125;</code></pre><h3 id="P2812-校园网络【-USACO-Network-of-Schools加强版】-洛谷-计算机科学教育新生态-luogu-com-cn"><a href="#P2812-校园网络【-USACO-Network-of-Schools加强版】-洛谷-计算机科学教育新生态-luogu-com-cn" class="headerlink" title="P2812 校园网络【[USACO]Network of Schools加强版】 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)"></a><a href="https://www.luogu.com.cn/problem/P2812">P2812 校园网络【[USACO]Network of Schools加强版】 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)</a></h3><h4 id="题目背景"><a href="#题目背景" class="headerlink" title="题目背景"></a>题目背景</h4><p>浙江省的几所 OI 强校的神犇发明了一种人工智能，可以 AC 任何题目，所以他们决定建立一个网络来共享这个软件。但是由于他们脑力劳动过多导致全身无力身体被♂掏♂空，他们来找你帮助他们。</p><h4 id="题目描述-1"><a href="#题目描述-1" class="headerlink" title="题目描述"></a>题目描述</h4><p>共有 $n$ 所学校 $(1 \leq n \leq 10000)$ 已知他们实现设计好的网络共 $m$ 条线路，为了保证高速，网络是单向的。现在请你告诉他们至少选几所学校作为共享软件的母机，能使每所学校都可以用上。再告诉他们至少要添加几条线路能使任意一所学校作为母机都可以使别的学校使用上软件。</p><h4 id="输入格式-1"><a href="#输入格式-1" class="headerlink" title="输入格式"></a>输入格式</h4><p>第一行一个正整数 $n$。</p><p>接下来 $n$ 行每行有若干个整数，用空格隔开。</p><p>第 $i+1$ 行，每行输入若干个非零整数 $x$，表示从 $i$ 到 $x$ 有一条线路。以 $0$ 作为结束标志。</p><h4 id="输出格式-1"><a href="#输出格式-1" class="headerlink" title="输出格式"></a>输出格式</h4><p>第一行一个整数，表示至少选几所学校作为共享软件的母机，能使每所学校都可以用上。</p><p>第二行一个整数，表示至少要添加几条线路能使任意一所学校作为母机都可以使别的学校使用上软件。</p><h4 id="样例-1-1"><a href="#样例-1-1" class="headerlink" title="样例 #1"></a>样例 #1</h4><h4 id="样例输入-1-1"><a href="#样例输入-1-1" class="headerlink" title="样例输入 #1"></a>样例输入 #1</h4><pre><code>52 04 05 01 00</code></pre><h4 id="样例输出-1-1"><a href="#样例输出-1-1" class="headerlink" title="样例输出 #1"></a>样例输出 #1</h4><pre><code>22</code></pre><h4 id="提示-1"><a href="#提示-1" class="headerlink" title="提示"></a>提示</h4><p>实际上，$1 \leq n \leq 10000$，$1\le $ 边数 $\le 50000$。</p><h4 id="思路："><a href="#思路：" class="headerlink" title="思路："></a>思路：</h4><p>依旧是$scc$缩点形成$DAG$，对于第一个问题：入度为零的点个数即为最少学校，因为入度为零的点为每一个联通图的初始节点。对于第二个问题：$max$(入度为零的点,出度为零的点）即为答案，因为要整体成强连通分量只能把所有把现有的边入度和出度都为零，因为连接一条边是入度出度都++，所以输出$max$入度或者出度即可。</p><h4 id="代码："><a href="#代码：" class="headerlink" title="代码："></a>代码：</h4><pre><code class="lang-c++">int dfn[N],low[N],cnt,sz[N],scc[N],sc,d[N],ud[N];stack&lt;int&gt;st;vector&lt;int&gt;e[N],ex[N];bool vis[N];queue&lt;int&gt;q;void tarjan(int u)&#123;    dfn[u]=low[u]=++cnt;    st.push(u),vis[u]=true;    for(auto &amp;to:e[u])&#123;        if(!dfn[to])&#123;            tarjan(to);            low[u]=min(low[u],low[to]);        &#125;        else if(vis[to])&#123;            low[u]=min(low[u],dfn[to]);        &#125;    &#125;    if(dfn[u]==low[u])&#123;        sc++;        while(st.top()!=u)&#123;            scc[st.top()]=sc;            vis[st.top()]=0;            st.pop();        &#125;        scc[st.top()]=sc;        vis[st.top()]=0;        st.pop();    &#125;&#125;void solve()&#123;    int n;cin&gt;&gt;n;    for(int i=1;i&lt;=n;i++)&#123;        int x;        while(cin&gt;&gt;x,x)&#123;            e[i].pb(x);        &#125;    &#125;    for(int i=1;i&lt;=n;i++)    if(!dfn[i])tarjan(i);    int ans1=0,ans2=0;    for(int i=1;i&lt;=n;i++)&#123;        int u=scc[i];        for(auto &amp;to:e[i])&#123;            int v=scc[to];            if(u==v)continue;            d[v]++,ud[u]++;        &#125;    &#125;    for(int i=1;i&lt;=sc;i++)    &#123;        if(!d[i])ans1++;        if(!ud[i])ans2++;    &#125;    cout&lt;&lt;ans1&lt;&lt;&quot;\n&quot;;    if(sc==1)    cout&lt;&lt;0&lt;&lt;&quot;\n&quot;;    else cout&lt;&lt;max(ans1,ans2)&lt;&lt;&quot;\n&quot;;&#125;</code></pre>]]></content:encoded>
      
      
      <category domain="https://lifexoryoung.cn/categories/%E7%AC%94%E8%AE%B0/">笔记</category>
      
      
      <category domain="https://lifexoryoung.cn/tags/dfs/">dfs</category>
      
      <category domain="https://lifexoryoung.cn/tags/%E5%BC%BA%E8%BF%9E%E9%80%9A%E5%88%86%E9%87%8F/">强连通分量</category>
      
      <category domain="https://lifexoryoung.cn/tags/tarjan/">tarjan</category>
      
      <category domain="https://lifexoryoung.cn/tags/%E6%8B%93%E6%89%91/">拓扑</category>
      
      
      <comments>https://lifexoryoung.cn/2024/06/10/%E5%BC%BA%E8%BF%9E%E9%80%9A%E5%88%86%E9%87%8F-scc%E7%BC%A9%E7%82%B9-tarjan/#disqus_thread</comments>
      
    </item>
    
    <item>
      <title>lca与树上（路径交、并，直径）问题</title>
      <link>https://lifexoryoung.cn/2024/05/27/lca%E4%B8%8E%E6%A0%91%E4%B8%8A%EF%BC%88%E8%B7%AF%E5%BE%84%E4%BA%A4%E3%80%81%E5%B9%B6%EF%BC%8C%E7%9B%B4%E5%BE%84%EF%BC%89%E9%97%AE%E9%A2%98/</link>
      <guid>https://lifexoryoung.cn/2024/05/27/lca%E4%B8%8E%E6%A0%91%E4%B8%8A%EF%BC%88%E8%B7%AF%E5%BE%84%E4%BA%A4%E3%80%81%E5%B9%B6%EF%BC%8C%E7%9B%B4%E5%BE%84%EF%BC%89%E9%97%AE%E9%A2%98/</guid>
      <pubDate>Mon, 27 May 2024 07:56:00 GMT</pubDate>
      
      <description>&lt;p&gt;最近的一些比赛中经常用到树上$lca$的常见模型，整理一下：&lt;/p&gt;</description>
      
      
      
      <content:encoded><![CDATA[<p>最近的一些比赛中经常用到树上$lca$的常见模型，整理一下：</p><span id="more"></span><p>首先整理一下$LCA$的四种求法：</p><p>1.倍增$LCA$：预处理$O(nlogn)$  单次查询$O(logn)$</p><p>通过$bfs$预处理节点深度和$st$表倍增处理祖宗节点，在查询的时候用倍增先将两点跳到统一深度，再找同祖宗节点的最深节点</p><pre><code class="lang-c++">int n,depth[N],f[N][19];vector&lt;int&gt;e[N];void bfs(int root)&#123;    memset(depth,0x3f,sizeof depth);    depth[0]=0,depth[root]=1;//0为st表的哨兵    queue&lt;int&gt;q;    q.push(root);    while(q.size())&#123;        int ver=q.front();        q.pop();        for(auto &amp;to:e[ver])&#123;            if(depth[to]&gt;depth[ver]+1)&#123;                depth[to]=depth[ver]+1;                f[to][0]=ver;                for(int i=1;i&lt;=18;i++)                f[to][i]=f[f[to][i-1]][i-1];            &#125;        &#125;    &#125;&#125;int lca(int a,int b)&#123;    if(depth[a]&lt;depth[b])swap(a,b);    for(int i=18;i&gt;=0;i--)&#123;        if(depth[f[a][i]]&lt;=depth[b])        a=f[a][i];    &#125;    if(a==b)return a;    for(int i=18;i&gt;=0;i--)&#123;        if(f[a][i]!=f[b][i])        a=f[a][i],b=f[b][i];    &#125;    return f[a][0];&#125;</code></pre><p>2.$Tarjan$离线$LCA$: 总体时间复杂度$O(n+q)$ ，$n$为节点 $q$为查询次数</p><p>暂定</p><p>3.在线$RMQLCA$：预处理$O(nlogn)$ 单次查询$O(1)$</p><p>通过$dfs$处理欧拉序及其深度，并保存每个节点第一次出现位置，通过$st$表维护区间深度最小值即可</p><pre><code class="lang-c++">int n,q,root,depth[N&lt;&lt;1],f[N&lt;&lt;1][19],se[N&lt;&lt;1],tot,Log[N&lt;&lt;1],id[N];vector&lt;int&gt;e[N];void dfs(int u,int d,int fa)&#123;    se[++tot]=u;    id[u]=tot;    depth[tot]=d;    for(auto &amp;to:e[u])&#123;        if(to==fa)continue;        dfs(to,d+1,u);        se[++tot]=u;        depth[tot]=d;    &#125;&#125;int lca(int l,int r)&#123;    int k=Log[r-l+1];    return depth[f[l][k]]&lt;depth[f[r-(1&lt;&lt;k)+1][k]]?    se[f[l][k]]:se[f[r-(1&lt;&lt;k)+1][k]];&#125;void solve()&#123;    cin&gt;&gt;n&gt;&gt;q&gt;&gt;root;    for(int i=1;i&lt;n;i++)&#123;        int u,v;cin&gt;&gt;u&gt;&gt;v;        e[u].pb(v);        e[v].pb(u);    &#125;    dfs(root,1,0);    Log[1]=0,Log[2]=1;    for(int i=3;i&lt;=tot;i++)    Log[i]=Log[i/2]+1;    for(int i=1;i&lt;=tot;i++)f[i][0]=i;    for(int j=1;j&lt;=Log[tot];j++)    for(int i=1;i+(1&lt;&lt;j)-1&lt;=tot;i++)    if(depth[f[i][j-1]]&lt;depth[f[i+(1&lt;&lt;(j-1))][j-1]])f[i][j]=f[i][j-1];    else f[i][j]=f[i+(1&lt;&lt;(j-1))][j-1];    while(q--)&#123;        int u,v;cin&gt;&gt;u&gt;&gt;v;        int l=id[u],r=id[v];        if(l&gt;r)swap(l,r);    &#125;&#125;</code></pre><p>4.树链剖分$LCA$:预处理$O(n)$  单次查询$O(logn)$</p><p>暂定</p><p>树上$LCA$的几种常用模型：</p><p>1.动态维护树的直径</p><p>2.树上路径的交</p><p>3.树上路径的并</p>]]></content:encoded>
      
      
      <category domain="https://lifexoryoung.cn/categories/%E7%AC%94%E8%AE%B0/">笔记</category>
      
      <category domain="https://lifexoryoung.cn/categories/%E7%AC%94%E8%AE%B0/%E8%A1%A5%E9%A2%98/">补题</category>
      
      
      <category domain="https://lifexoryoung.cn/tags/%E5%9B%BE%E8%AE%BA/">图论</category>
      
      <category domain="https://lifexoryoung.cn/tags/%E6%A0%91%E8%AE%BA/">树论</category>
      
      <category domain="https://lifexoryoung.cn/tags/LCA/">LCA</category>
      
      <category domain="https://lifexoryoung.cn/tags/Tarjan/">Tarjan</category>
      
      <category domain="https://lifexoryoung.cn/tags/st%E8%A1%A8/">st表</category>
      
      <category domain="https://lifexoryoung.cn/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">数据结构</category>
      
      <category domain="https://lifexoryoung.cn/tags/%E5%B9%B6%E6%9F%A5%E9%9B%86/">并查集</category>
      
      <category domain="https://lifexoryoung.cn/tags/%E7%BA%BF%E6%AE%B5%E6%A0%91/">线段树</category>
      
      <category domain="https://lifexoryoung.cn/tags/dfs/">dfs</category>
      
      <category domain="https://lifexoryoung.cn/tags/bfs/">bfs</category>
      
      
      <comments>https://lifexoryoung.cn/2024/05/27/lca%E4%B8%8E%E6%A0%91%E4%B8%8A%EF%BC%88%E8%B7%AF%E5%BE%84%E4%BA%A4%E3%80%81%E5%B9%B6%EF%BC%8C%E7%9B%B4%E5%BE%84%EF%BC%89%E9%97%AE%E9%A2%98/#disqus_thread</comments>
      
    </item>
    
    <item>
      <title>2023 Hubei Provincial Collegiate Programming Contest</title>
      <link>https://lifexoryoung.cn/2024/04/03/2023%20Hubei%20Provincial%20Collegiate%20Programming%20Contest/</link>
      <guid>https://lifexoryoung.cn/2024/04/03/2023%20Hubei%20Provincial%20Collegiate%20Programming%20Contest/</guid>
      <pubDate>Wed, 03 Apr 2024 03:37:00 GMT</pubDate>
      
      <description>&lt;p&gt;&lt;a href=&quot;https://codeforces.com/gym/104337/problem/I&quot;&gt;Problem - I - step&lt;/a&gt;&lt;/p&gt;</description>
      
      
      
      <content:encoded><![CDATA[<p><a href="https://codeforces.com/gym/104337/problem/I">Problem - I - step</a></p><span id="more"></span><p>题目：</p><p>给你 $n$ 个环，$i$ /th 环的长度是 $p_i(1\le i \le n)$ 。对于第 $i$ 个环， $p_i$ 的下一个位置是 $1$ 。一开始，每个环的 $1$ 位置都有一匹小马，而且小马的移动速度一天比一天快。</p><p>具体来说，小马第一天移动 $1$ 步，第二天移动 $2$ 步，以此类推。从形式上看，小马将在$k$ / $k \in \mathbb{N}$ 的第 $k$ 天移动 $k$ 步。</p><p>很明显，在某一天，所有的小马都会到达位置 $1$ 。现在，米库想知道最早的一天 $m$ ($0$ 除外)，所有的 $n$ 小马将到达位置 $1$ 。</p><p><strong>输入</strong></p><p>输入的第一行包含一个正整数 $n$（$1 \le n \le 10^5$），表示环的数量。</p><p>输入的第二行包含 $n$ 个正整数 $p_i$（$1 \le p_i \le 10^7$），表示每个环的长度。</p><p><strong>保证 $\{p_1, p_2, \ldots, p_n\}$ 的最小公倍数（LCM）不超过 $10^{18}$。</strong> 提醒一下，$\{p_1, p_2, \ldots, p_n\}$ 的最小公倍数（LCM）表示集合 $\{p_1, p_2, \ldots, p_n\}$ 中所有元素的最小公倍数。</p><p><strong>输出</strong></p><p>输出一个正整数，表示所有 $n$ 小马到达位置 $1$ 的最早日期。</p><p>分析：</p>]]></content:encoded>
      
      
      <category domain="https://lifexoryoung.cn/categories/%E8%A1%A5%E9%A2%98/">补题</category>
      
      <category domain="https://lifexoryoung.cn/categories/%E8%A1%A5%E9%A2%98/codeforce/">codeforce</category>
      
      
      <category domain="https://lifexoryoung.cn/tags/%E6%89%A9%E5%B1%95%E6%AC%A7%E5%87%A0%E9%87%8C%E5%BE%97/">扩展欧几里得</category>
      
      
      <comments>https://lifexoryoung.cn/2024/04/03/2023%20Hubei%20Provincial%20Collegiate%20Programming%20Contest/#disqus_thread</comments>
      
    </item>
    
    <item>
      <title>2024 ICPC National Invitational Collegiate Programming Contest, Wuhan Site（2024武汉邀请赛）</title>
      <link>https://lifexoryoung.cn/2024/04/03/2024%20ICPC%20National%20Invitational%20Collegiate%20Programming%20Contest,%20Wuhan%20Site%EF%BC%882024%E6%AD%A6%E6%B1%89%E9%82%80%E8%AF%B7%E8%B5%9B%EF%BC%89/</link>
      <guid>https://lifexoryoung.cn/2024/04/03/2024%20ICPC%20National%20Invitational%20Collegiate%20Programming%20Contest,%20Wuhan%20Site%EF%BC%882024%E6%AD%A6%E6%B1%89%E9%82%80%E8%AF%B7%E8%B5%9B%EF%BC%89/</guid>
      <pubDate>Wed, 03 Apr 2024 03:37:00 GMT</pubDate>
      
      <description>&lt;h3 id=&quot;题目Problem-B-Countless-Me-Codeforces：&quot;&gt;&lt;a href=&quot;#题目Problem-B-Countless-Me-Codeforces：&quot; class=&quot;headerlink&quot; title=&quot;题目Problem - B. Countless Me- Codeforces：&quot;&gt;&lt;/a&gt;题目&lt;a href=&quot;https://codeforces.com/gym/105143/problem/B&quot;&gt;Problem - B. Countless Me- Codeforces&lt;/a&gt;：&lt;/h3&gt;</description>
      
      
      
      <content:encoded><![CDATA[<h3 id="题目Problem-B-Countless-Me-Codeforces："><a href="#题目Problem-B-Countless-Me-Codeforces：" class="headerlink" title="题目Problem - B. Countless Me- Codeforces："></a>题目<a href="https://codeforces.com/gym/105143/problem/B">Problem - B. Countless Me- Codeforces</a>：</h3><span id="more"></span><h4 id="分析："><a href="#分析：" class="headerlink" title="分析："></a>分析：</h4><p>假设最优的情况下，每个值为 $x_1$,$x_2$…$x_n$,则使给定序列变为最优值只需要一次，整个序列只需要n次，所以可以把序列变成任意序列。因为越$ | $越大,所以不难想到拆位并尽可能让高位置$0$。</p><p>我们不妨把所有值相加为$now$，从第$（1&lt;&lt;30）$ 开始高位往低位分析。设当前位为第$i$位，如果$now \le ((1&lt;&lt;i)-1)*n$ 那么可以当前位置0，否则我们尽量把当前位填更多$1$。（因为当前位置越多$1$,后面越容易置$0$,且因为当前位置$1$,拆成后面一定为偶数个$1$,在之后不能置$1$的情况下，一定会往前进位，那么现在置$1$不会更坏）</p><h4 id="代码："><a href="#代码：" class="headerlink" title="代码："></a>代码：</h4><pre><code class="lang-c++">void solve()&#123;    int n,res=0;    cin&gt;&gt;n;    for(int i=1;i&lt;=n;i++)&#123;        int x;cin&gt;&gt;x;        res+=x;    &#125;    int ans=0;    for(int i=30;i&gt;=0;i--)&#123;        int ver=((1ll&lt;&lt;i)-1)*n;        if(res&gt;ver)ans|=(1ll&lt;&lt;i),res-=min(n,res/(1ll&lt;&lt;i))*(1ll&lt;&lt;i);    &#125;    cout&lt;&lt;ans&lt;&lt;&quot;\n&quot;;&#125;</code></pre>]]></content:encoded>
      
      
      <category domain="https://lifexoryoung.cn/categories/%E8%A1%A5%E9%A2%98/">补题</category>
      
      <category domain="https://lifexoryoung.cn/categories/%E8%A1%A5%E9%A2%98/codeforce/">codeforce</category>
      
      
      <category domain="https://lifexoryoung.cn/tags/%E6%89%A9%E5%B1%95%E6%AC%A7%E5%87%A0%E9%87%8C%E5%BE%97/">扩展欧几里得</category>
      
      
      <comments>https://lifexoryoung.cn/2024/04/03/2024%20ICPC%20National%20Invitational%20Collegiate%20Programming%20Contest,%20Wuhan%20Site%EF%BC%882024%E6%AD%A6%E6%B1%89%E9%82%80%E8%AF%B7%E8%B5%9B%EF%BC%89/#disqus_thread</comments>
      
    </item>
    
  </channel>
</rss>
