<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1953325079793449971</id><updated>2026-04-21T00:13:15.343+02:00</updated><title type='text'>Algorithms Weekly by Petr Mitrichev</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>579</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-3936411260142835568</id><published>2026-02-26T11:44:00.004+01:00</published><updated>2026-02-26T11:44:55.371+01:00</updated><title type='text'>Codeforces Blitz Cup 2026 Round of 32 livestream</title><content type='html'>&lt;p&gt;Codeforces is running &lt;a href=&quot;https://codeforces.com/blog/entry/150813&quot;&gt;Blitz Cup 2026&lt;/a&gt;, and my Round of 32 match against&amp;nbsp;feecIe6418 starts in about 1 hour! You can watch &lt;a href=&quot;https://youtu.be/8G99e3Z3SU4&quot;&gt;my livestream&lt;/a&gt;&amp;nbsp;or&amp;nbsp;&lt;a href=&quot;https://codeforces.com/spectator/ranklist/Round_3__Petr_vs_feecIe6418_nRRmXYJm&quot;&gt;the scoreboard&lt;/a&gt;. Here is the &lt;a href=&quot;https://codeforces.com/publish/blitz2026/bracket.html&quot;&gt;full bracket&lt;/a&gt;.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/3936411260142835568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2026/02/codeforces-blitz-cup-2026-round-of-32.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/3936411260142835568'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/3936411260142835568'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2026/02/codeforces-blitz-cup-2026-round-of-32.html' title='Codeforces Blitz Cup 2026 Round of 32 livestream'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-8431204081091704746</id><published>2026-02-08T07:42:00.002+01:00</published><updated>2026-02-08T08:06:58.704+01:00</updated><title type='text'>EUC 2026 contest day</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYsYs0Pm9qIQFjkWx2HQ3YONLYppuwcdXCCBqzGxMYO62FCKtMz9dtd5hBORsVRwtEji_DQHp5qFekeKleI9E7F32GROBKcUC8gjVsodamI3a3OqRxc4Ul-tK6Sp7GV2x1c2LafbhroMODy1-2xGR3_8D3r6YOSXyGYBTAiemejCnxSZXxfMkh2obW-Xc/s2048/55079041952_867d1bc767_k.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1365&quot; data-original-width=&quot;2048&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYsYs0Pm9qIQFjkWx2HQ3YONLYppuwcdXCCBqzGxMYO62FCKtMz9dtd5hBORsVRwtEji_DQHp5qFekeKleI9E7F32GROBKcUC8gjVsodamI3a3OqRxc4Ul-tK6Sp7GV2x1c2LafbhroMODy1-2xGR3_8D3r6YOSXyGYBTAiemejCnxSZXxfMkh2obW-Xc/w640-h426/55079041952_867d1bc767_k.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;ICPC EUC 2026 starts in about two hours (&lt;a href=&quot;https://www.timeanddate.com/worldclock/fixedtime.html?msg=ICPC+EUC+2026&amp;amp;iso=20260208T0930&amp;amp;p1=262&amp;amp;ah=5&quot;&gt;9:30 Warsaw time&lt;/a&gt;, photo on the left from &lt;a href=&quot;https://news.icpc.global/galleryEU/?album=2026&amp;amp;event=Photo+Tour&quot;&gt;the official gallery&lt;/a&gt;). Here are some useful links:&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a href=&quot;https://euc.icpc.global/&quot;&gt;Official website&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://euc.icpc.global/home-2026/teams/&quot;&gt;Teams&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://euc.icpc.global/scoreboard/2026&quot;&gt;Scoreboard&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://euc.icpc.global/problems/2026/&quot;&gt;Problems&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=hxS2AvOAjQ8&amp;amp;list=PLaSPkFE9cpGTZQKrJzUHfuhaxO6Zmzgyn&amp;amp;index=2&quot;&gt;Livestream&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Note that these problems will be used for the Universal Cup next weekend, so please don&#39;t look at them (and don&#39;t watch the livestream I guess?) if you are planning to participate there.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the other case, do tune in!&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/8431204081091704746/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2026/02/euc-2026-contest-day.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/8431204081091704746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/8431204081091704746'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2026/02/euc-2026-contest-day.html' title='EUC 2026 contest day'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYsYs0Pm9qIQFjkWx2HQ3YONLYppuwcdXCCBqzGxMYO62FCKtMz9dtd5hBORsVRwtEji_DQHp5qFekeKleI9E7F32GROBKcUC8gjVsodamI3a3OqRxc4Ul-tK6Sp7GV2x1c2LafbhroMODy1-2xGR3_8D3r6YOSXyGYBTAiemejCnxSZXxfMkh2obW-Xc/s72-w640-h426-c/55079041952_867d1bc767_k.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-7842441090758209580</id><published>2026-02-07T12:04:00.001+01:00</published><updated>2026-02-07T12:04:17.845+01:00</updated><title type='text'>A shift week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgutmgZ_hkIXecOuEOegJbiCuXLfotnmRWktl20Tn7_uvKt0_PSAvWCQsMjvEVDseqn9NP5GOi9CGtye6OIUANvDzqBgqdtkdl_85aVupIcsqu7OYm7KvSXGsBswMzVOY6Z3Gy-xzS_bS8XJ75Cre-rE8T9WdWh-DA_MoWgStzsEomgPxgbSE9MG3dz8K8&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;232&quot; data-original-width=&quot;1024&quot; height=&quot;146&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgutmgZ_hkIXecOuEOegJbiCuXLfotnmRWktl20Tn7_uvKt0_PSAvWCQsMjvEVDseqn9NP5GOi9CGtye6OIUANvDzqBgqdtkdl_85aVupIcsqu7OYm7KvSXGsBswMzVOY6Z3Gy-xzS_bS8XJ75Cre-rE8T9WdWh-DA_MoWgStzsEomgPxgbSE9MG3dz8K8=w640-h146&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The Dec 22 - Dec 29 week wrapped up the competitive 2025 on the major platforms. The 4th Universal Cup. Stage 10: Grand Prix of Wrocław took place on Saturday (&lt;a href=&quot;https://contest.ucup.ac/contest/2814&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2814&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://cerc25.ii.uni.wroc.pl/results.html&quot;&gt;onsite results&lt;/a&gt;, &lt;a href=&quot;https://assets.ucup.ac/tutorials/tutorials-4-10-en.pdf&quot;&gt;analysis&lt;/a&gt;). Team USA1 were not the first to finish, but they were still the fastest overall, and extended their streak of 8 (!) won rounds in a row. Well done!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjEb26Mi9P1LkRVZoGgWFMbuSbPnT8oyPakN9ZaQ7dBM2wIBtDVDAW_kyga9ywyMEKI2ee2od9s3ucm-QLOZDkXOjoddySy_0j2FYi8iB_ksPMdo6NrmavrJGyhibyQkgGtJrnHJ3A-FIalhmhMLaPgFNeWnYHm4IhOWAmZ-PDsyquvRjsoyq3Q8qJ98XI&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;272&quot; data-original-width=&quot;1130&quot; height=&quot;154&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjEb26Mi9P1LkRVZoGgWFMbuSbPnT8oyPakN9ZaQ7dBM2wIBtDVDAW_kyga9ywyMEKI2ee2od9s3ucm-QLOZDkXOjoddySy_0j2FYi8iB_ksPMdo6NrmavrJGyhibyQkgGtJrnHJ3A-FIalhmhMLaPgFNeWnYHm4IhOWAmZ-PDsyquvRjsoyq3Q8qJ98XI=w640-h154&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Codeforces Good Bye 2025 followed the same day (&lt;a href=&quot;https://codeforces.com/contest/2178&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2178/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/149548&quot;&gt;analysis&lt;/a&gt;). While the round lasted 3 hours, the top three needed just two of those to solve all problems. Similar to the above round, being first to finish did not mean first place, though, as Benq was a bit slower on the medium problems and therefore jiangly could overtake him. Congratulations!&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I have enjoyed solving the problems and was making good progress, but it was nowhere near as fast, as problem F by itself took me over an hour of iterations, stress testing etc.&amp;nbsp;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjj31sFDjIgFH_hFMeSvObqRqf-bhjE2_2mVN6xJzD8F3HoyNPdZXZsoUE6j93mbP7RHRGcKm-RPBfyc6sPFVqa5NFH_uAifHk9K4sOiBoHUfJEOzO-zwKAZN5MENgz3WOSc7waP22rmQ6PojTEPUEW4shlpiZ3Mtwg5iroiLB4M9B1WdUif3nl7Ufqe88&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;336&quot; data-original-width=&quot;826&quot; height=&quot;260&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjj31sFDjIgFH_hFMeSvObqRqf-bhjE2_2mVN6xJzD8F3HoyNPdZXZsoUE6j93mbP7RHRGcKm-RPBfyc6sPFVqa5NFH_uAifHk9K4sOiBoHUfJEOzO-zwKAZN5MENgz3WOSc7waP22rmQ6PojTEPUEW4shlpiZ3Mtwg5iroiLB4M9B1WdUif3nl7Ufqe88=w640-h260&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;AtCoder Grand Contest 076 took place on Sunday (&lt;a href=&quot;https://atcoder.jp/contests/agc076/tasks&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://atcoder.jp/contests/agc076/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://atcoder.jp/contests/agc076/editorial&quot;&gt;analysis&lt;/a&gt;). It turns out that it was indeed possible to qualify for AWTF with a win after a relatively poor season, only it was noimi and not myself who has achieved that feat. Well done!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Quite unsually for an AGC I was able to solve A very quickly, but did not score any points after that. In problem B, I have empirically discovered that the answer is always 1 or 2, but could not figure out a condition to separate those two cases, not to mention the actual sequence of steps to achieve that number. In problem C my incorrect solutions were quite close to the one described in the editorial by the idea, but not close enough by the details. At the end of the contest, I have tried to solve E as a heuristic problem, trying various greedy approaches with local optimizations on top, also without much success. Well, better luck next year!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here is that heuristic-inviting &lt;a href=&quot;https://atcoder.jp/contests/agc076/tasks/agc076_e&quot;&gt;problem E&lt;/a&gt;: you are given at most 250000 vectors, and need to choose a subset that maximizes the value of (squared length of the sum of the chosen vectors) minus three times (sum of squared lengths of the chosen vectors). Can you find an exact solution?&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjjRVx47bHDrxm04IHh2UA4k3yh1w_EpdoDRSqEVp2sNshhq5EjHWZxtHlY9lFQYpiWXMYO76d0DKNFUliYkvZGqFSm1_NEPyVoNs6EkWxX_5ZSJQvSKxXJQ85m0iduI8e9uztu19awkmXxVYzU14zjVdd-PPO588IShnrGyJF7v47kwuIxA0KrMsze4-k&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;668&quot; data-original-width=&quot;1029&quot; height=&quot;416&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjjRVx47bHDrxm04IHh2UA4k3yh1w_EpdoDRSqEVp2sNshhq5EjHWZxtHlY9lFQYpiWXMYO76d0DKNFUliYkvZGqFSm1_NEPyVoNs6EkWxX_5ZSJQvSKxXJQ85m0iduI8e9uztu19awkmXxVYzU14zjVdd-PPO588IShnrGyJF7v47kwuIxA0KrMsze4-k=w640-h416&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;This round wrapped up the race for the 2026 World Tour Finals (&lt;a href=&quot;https://clist.by/standings/atcoder-race-ranking-2025-algorithm-57173720/&quot;&gt;results&lt;/a&gt;, top 12 on the left). Everyone with &amp;gt;=100 points qualified, but people had wildly different ways to achieve that amount of points, with some qualifying thanks to a round victory, and some never placing higher than fourth in any particular round. I&#39;m looking forward to yet another exciting final in Japan!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It is also notable that some usual suspects did not qualify this time, including zhoukangyang who was &lt;a href=&quot;https://clist.by/standings/atcoder-race-ranking-2024-algorithm-49154495/&quot;&gt;first&lt;/a&gt; and &lt;a href=&quot;https://blog.mitrichev.ch/2023/12/a-three-step-week.html&quot;&gt;first&lt;/a&gt; in qualification in the previous two seasons, and &lt;a href=&quot;https://blog.mitrichev.ch/2025/07/a-21st-century-week.html&quot;&gt;first&lt;/a&gt; and &lt;a href=&quot;https://blog.mitrichev.ch/2024/07/awtf24-contest.html&quot;&gt;second&lt;/a&gt; in the last two World Tour Finals. Better luck next year as well!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTCqIqTj_c9Hv1oYzcop5i99UfLuRucT92HVnBKjNg4pvBHkRKGiCKahOGvYydTmbjUOiWCrPWgrOaXHdYXp1AdHkFM_pqLRCnbb1gBZeiI3789ORYpKBhNNIsjI_Bs7pPTJqWdafjpyJTbOZtXqqYDEpH80WU85wynP4H8IDuToPG5Rlb_nR_KCs2ODU/s4080/PXL_20260126_171657491.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTCqIqTj_c9Hv1oYzcop5i99UfLuRucT92HVnBKjNg4pvBHkRKGiCKahOGvYydTmbjUOiWCrPWgrOaXHdYXp1AdHkFM_pqLRCnbb1gBZeiI3789ORYpKBhNNIsjI_Bs7pPTJqWdafjpyJTbOZtXqqYDEpH80WU85wynP4H8IDuToPG5Rlb_nR_KCs2ODU/w640-h482/PXL_20260126_171657491.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In &lt;a href=&quot;https://blog.mitrichev.ch/2025/12/a-digging-week.html&quot;&gt;my previous summary&lt;/a&gt;, I have mentioned&amp;nbsp;&lt;a href=&quot;https://atcoder.jp/contests/agc075/tasks/agc075_c&quot;&gt;another AtCoder problem&lt;/a&gt;: you are given two sequences of integers&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;and&amp;nbsp;&lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;of the same length &lt;i&gt;n&lt;/i&gt; up to 2*10&lt;sup&gt;5&lt;/sup&gt;, 1&amp;lt;=&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=10&lt;sup&gt;9&lt;/sup&gt;, 0&amp;lt;=&lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=30. We will permute the sequence&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;arbitrarily, and then compute sum(&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;gt;&amp;gt;&lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;), where &amp;gt;&amp;gt; denotes the bitwise shift right. How many of the &lt;i&gt;n&lt;/i&gt;! permutations yield the smallest possible value of that sum? You need to print the answer modulo 998244353.&lt;p&gt;&lt;/p&gt;
&lt;p&gt;
First, let us sort both arrays, so we can assume they are sorted below.
Intuitively, it feels that all permutations of &lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; that deliver the minimum
must be sorted or almost sorted. To make further progress, we can either implement
a brute force approach to find out experimentally what does &lt;i&gt;almost&lt;/i&gt; mean exactly, or make
the intuitive argument more formal, with the same goal. 
&lt;/p&gt;
&lt;p&gt;
Suppose we have only two elements. If &lt;i&gt;a&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt; = &lt;i&gt;a&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; 
or &lt;i&gt;b&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt; = &lt;i&gt;b&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt;, then they can be swapped freely without changing
our target value. Now consider the case when they are distinct: &lt;i&gt;a&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt; &amp;lt; &lt;i&gt;a&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; and
&lt;i&gt;b&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt; &amp;lt; &lt;i&gt;b&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt;. When is it OK to swap them?
&lt;/p&gt;
&lt;p&gt;
Since we&#39;re going to shift right by at least &lt;i&gt;b&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt;, it makes sense to introduce
&lt;i&gt;p&lt;/i&gt;&amp;nbsp;=&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt; &amp;gt;&amp;gt; &lt;i&gt;b&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt;, &lt;i&gt;q&lt;/i&gt;&amp;nbsp;=&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; &amp;gt;&amp;gt; &lt;i&gt;b&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt;,
and &lt;i&gt;r&lt;/i&gt;&amp;nbsp;=&amp;nbsp;&lt;i&gt;b&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt; - &lt;i&gt;b&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt;. Then we need the following to be true:
&lt;i&gt;p&lt;/i&gt; + &lt;i&gt;q&lt;/i&gt; &amp;gt;&amp;gt; &lt;i&gt;r&lt;/i&gt; = &lt;i&gt;q&lt;/i&gt; + &lt;i&gt;p&lt;/i&gt; &amp;gt;&amp;gt; &lt;i&gt;r&lt;/i&gt;, which is equivalent to
&lt;i&gt;q&lt;/i&gt; - &lt;i&gt;p&lt;/i&gt; = &lt;i&gt;q&lt;/i&gt; &amp;gt;&amp;gt; &lt;i&gt;r&lt;/i&gt; - &lt;i&gt;p&lt;/i&gt; &amp;gt;&amp;gt; &lt;i&gt;r&lt;/i&gt;.
&lt;/p&gt;
&lt;p&gt;
What happens to the difference of two numbers if we cut their last bit? It is not hard to check
that it stays the same in only one case: if the bigger number was even, and exactly 1 higher than
the smaller number. In all other cases it becomes smaller. So for the above condition to be true,
we need &lt;i&gt;q&lt;/i&gt;&amp;nbsp;=&amp;nbsp;&lt;i&gt;p&lt;/i&gt;&amp;nbsp;+ 1 and &lt;i&gt;q&lt;/i&gt; divisible by 2&lt;sup&gt;&lt;i&gt;r&lt;/i&gt;&lt;/sup&gt;. These are the only cases
where two distinct numbers can be swapped without increasing our target value.
&lt;/p&gt;
&lt;p&gt;
Now we will consider our arrays in blocks of equal &lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;. Consider the first such block:
&lt;i&gt;b&lt;/i&gt;&lt;sub&gt;0&lt;/sub&gt; = &lt;i&gt;b&lt;/i&gt;&lt;sub&gt;1&lt;/sub&gt;&amp;nbsp;= ... = &lt;i&gt;b&lt;/i&gt;&lt;sub&gt;&lt;i&gt;k&lt;/i&gt;-1&lt;/sub&gt; = 0,
&lt;i&gt;b&lt;sub&gt;k&lt;/sub&gt;&lt;/i&gt; &amp;gt; 0.
&lt;/p&gt;
&lt;p&gt;
Denote &lt;i&gt;x&lt;/i&gt; = &lt;i&gt;a&lt;sub&gt;k&lt;/sub&gt;&lt;/i&gt; if &lt;i&gt;a&lt;sub&gt;k&lt;/sub&gt;&lt;/i&gt; is even, and &lt;i&gt;a&lt;sub&gt;k&lt;/sub&gt;&lt;/i&gt; + 1 otherwise.
Therefore &lt;i&gt;x&lt;/i&gt; is always even. From the above argument, the only swaps we can do between this block and the rest of the array is swapping
the values &lt;i&gt;x&lt;/i&gt;-1 from the block with the values &lt;i&gt;x&lt;/i&gt; outside the block.
&lt;/p&gt;
&lt;p&gt;
Let us denote &lt;i&gt;c&lt;/i&gt; as the number of &lt;i&gt;i&lt;/i&gt; such that &lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; = &lt;i&gt;x&lt;/i&gt; - 1 and &lt;i&gt;i&lt;/i&gt; &amp;lt; &lt;i&gt;k&lt;/i&gt;,
&lt;i&gt;d&lt;/i&gt; as the number of &lt;i&gt;i&lt;/i&gt; such that &lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; = &lt;i&gt;x&lt;/i&gt; - 1 and &lt;i&gt;i&lt;/i&gt; &amp;gt;= &lt;i&gt;k&lt;/i&gt;,
&lt;i&gt;e&lt;/i&gt; as the number of &lt;i&gt;i&lt;/i&gt; such that &lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; = &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;i&lt;/i&gt; &amp;lt; &lt;i&gt;k&lt;/i&gt;,
&lt;i&gt;f&lt;/i&gt; as the number of &lt;i&gt;i&lt;/i&gt; such that &lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; = &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;i&lt;/i&gt; &amp;gt;= &lt;i&gt;k&lt;/i&gt;.
Note that we always have either &lt;i&gt;d&lt;/i&gt; = 0, or &lt;i&gt;e&lt;/i&gt; = 0, or both.
&lt;/p&gt;
&lt;p&gt;
Suppose we decided to do &lt;i&gt;g&lt;/i&gt; swaps of the above form (&lt;i&gt;x&lt;/i&gt;&amp;nbsp;- 1 from the block with &lt;i&gt;x&lt;/i&gt; from the rest).
Then we have (&lt;i&gt;c&lt;/i&gt; + &lt;i&gt;d&lt;/i&gt; choose &lt;i&gt;c&lt;/i&gt; - &lt;i&gt;g&lt;/i&gt;) ways to choose which values &lt;i&gt;x&lt;/i&gt;&amp;nbsp;- 1 go inside the block,
(&lt;i&gt;e&lt;/i&gt; + &lt;i&gt;f&lt;/i&gt; choose &lt;i&gt;e&lt;/i&gt; + &lt;i&gt;g&lt;/i&gt;) ways to choose which values &lt;i&gt;x&lt;/i&gt; go inside the block, and
(&lt;i&gt;k&lt;/i&gt; factorial) ways to permute the values inside the block. We need to multiply those three numbers by the answer
for the remaining subproblem, which is considering the arrays starting from the position &lt;i&gt;k&lt;/i&gt;, such that
&lt;i&gt;g&lt;/i&gt; values of &lt;i&gt;x&lt;/i&gt; have been replaced with &lt;i&gt;x&lt;/i&gt;&amp;nbsp;- 1, and we must make sure that those replaced values all
end up in the next &lt;i&gt;r&lt;/i&gt; blocks, where &lt;i&gt;r&lt;/i&gt; is the number of 0s at the end of the binary representation
of &lt;i&gt;x&lt;/i&gt;.
&lt;/p&gt;
&lt;p&gt;
Now, what happens when we consider the next block, the one where &lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;= 1? We can now shift all values
&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; right by 1, and denote &lt;i&gt;y&lt;/i&gt;&amp;nbsp;=&amp;nbsp;&lt;i&gt;x&lt;/i&gt; &amp;gt;&amp;gt; 1 (remember that &lt;i&gt;x&lt;/i&gt; is even), and now we can handle this
block in the same way we handled the block with &lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;= 0. The only difference is that now we have
the additional complexity that &lt;i&gt;g&lt;/i&gt; values of &lt;i&gt;y&lt;/i&gt; have been replaced with &lt;i&gt;y&lt;/i&gt;&amp;nbsp;- 1. Let us define &lt;i&gt;z&lt;/i&gt;&amp;nbsp;in the same way as &lt;i&gt;x&lt;/i&gt; was defined above, as the &quot;swap value&quot; between this new block and the rest, and suppose we decide to do &lt;i&gt;h&lt;/i&gt; swaps of&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;nbsp;- 1 from the block with&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;nbsp;from the rest.&lt;/p&gt;
&lt;p&gt;
We now have the following four cases:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;i&gt;y&lt;/i&gt; &amp;lt; &lt;i&gt;z&lt;/i&gt;&amp;nbsp;- 1. This means that all values of&amp;nbsp;&lt;i&gt;y&lt;/i&gt;&amp;nbsp;- 1&amp;nbsp;must go in this block, so they are not special anymore, and we can just sum up the number of ways over all values of &lt;i&gt;g&lt;/i&gt;&amp;nbsp;to get a single multiplier, and then solve this block exactly like the first block.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;y&lt;/i&gt; = &lt;i&gt;z&lt;/i&gt;&amp;nbsp;- 1. Here all values of&amp;nbsp;y - 1 also must go in this block, but additionally &lt;i&gt;g&lt;/i&gt; of the values of &lt;i&gt;y&lt;/i&gt; (=&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;nbsp;- 1) are no longer available for swapping forwards since they were already swapped backwards, so we need to subtract &lt;i&gt;g&lt;/i&gt; from the number of occurrences of&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;nbsp;- 1&amp;nbsp;in the block before computing the above combination numbers.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;y&lt;/i&gt; = &lt;i&gt;z&lt;/i&gt;. Here &lt;i&gt;g&lt;/i&gt; and &lt;i&gt;h&lt;/i&gt;&amp;nbsp;refer to the same swaps (&lt;i&gt;z&lt;/i&gt; with &lt;i&gt;z&lt;/i&gt; - 1), but done over different block boundaries. The number of occurrences of &lt;i&gt;z&lt;/i&gt; and &lt;i&gt;z&lt;/i&gt; - 1 within the block (which are again used to compute the above combination numbers) will therefore depend on the difference between &lt;i&gt;g&lt;/i&gt; and &lt;i&gt;h&lt;/i&gt;&amp;nbsp;(and we need to be careful to make sure&amp;nbsp;&lt;i&gt;h&lt;/i&gt; can be smaller than &lt;i&gt;g&lt;/i&gt;, too).&lt;/li&gt;
&lt;li&gt;&lt;i&gt;y&lt;/i&gt; &amp;gt; &lt;i&gt;z&lt;/i&gt;. Initially I thought this was impossible, but then an assertion failed in my solution :) And indeed, if in the first block the first value of the rest was 5, we&#39;d get &lt;i&gt;x&amp;nbsp;&lt;/i&gt;= 6 and therefore &lt;i&gt;y&lt;/i&gt; = 3; if the next block still had 5 after it, but now after the right shift we get &lt;i&gt;z&lt;/i&gt; = 2. After some thinking I realized that this case means that we have no place to put the values of &lt;i&gt;y&lt;/i&gt; - 1 without violating the restrictions, therefore we must only consider the value for &lt;i&gt;g&lt;/i&gt; = 0 for the previous block.&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;This finally gives rise to a polynomial dynamic programming solution. The state of this dynamic programming will be the bit number that is being considered (the value that we have already shifted all&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;right by, or alternatively the next value of&amp;nbsp;&lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;to consider), and the number &lt;i&gt;g&lt;/i&gt; of the swaps through the previous block boundary. Note that the other important values, such as the value of &lt;i&gt;y&lt;/i&gt; that participated in those swaps, or the position &lt;i&gt;k&lt;/i&gt; of the block, are uniquely determined by the state, and therefore do not need to be part of the state. And if we loop over the bit number on the outside, our dynamic programming array can be just one-dimensional. This solution has O(&lt;i&gt;n&lt;/i&gt;) states in total over all bits, but each transition can also be O(&lt;i&gt;n&lt;/i&gt;), therefore it is quadratic, and indeed it &lt;a href=&quot;https://atcoder.jp/contests/agc075/submissions/72946656&quot;&gt;gets TLE&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;However, the dynamic programming transition here is summation after multiplying by a combination number, which when expressed via factorials ends up being a product/fraction of factorials of &lt;i&gt;g&lt;/i&gt;, &lt;i&gt;h&lt;/i&gt;, and either &lt;i&gt;g&amp;nbsp;&lt;/i&gt;+&amp;nbsp;&lt;i&gt;h&lt;/i&gt; in the&amp;nbsp;&lt;i&gt;y&lt;/i&gt;&amp;nbsp;=&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;nbsp;- 1 case, or of &lt;i&gt;g&lt;/i&gt; - &lt;i&gt;h&lt;/i&gt; in the&amp;nbsp;&lt;i&gt;y&lt;/i&gt;&amp;nbsp;=&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;nbsp;case, and for that we have a trick that was &lt;a href=&quot;https://blog.mitrichev.ch/2016/11/a-fourier-combination-week.html&quot;&gt;described in this blog&lt;/a&gt; 9+ years ago: we can use fast polynomial multiplication via FFT, while using (const -&amp;nbsp;&lt;i&gt;g&lt;/i&gt;) and (&lt;i&gt;g&lt;/i&gt;&amp;nbsp;+&amp;nbsp;&lt;i&gt;h&lt;/i&gt;) as the monomial degrees in the&amp;nbsp;&lt;i&gt;y&lt;/i&gt;&amp;nbsp;=&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;nbsp;- 1 case to get (const +&amp;nbsp;&lt;i&gt;h&lt;/i&gt;) in the product, and using &lt;i&gt;g&lt;/i&gt;&amp;nbsp;and (const +&amp;nbsp;&lt;i&gt;h - g&lt;/i&gt;) as the monomial degrees in the&amp;nbsp;&lt;i&gt;y&lt;/i&gt;&amp;nbsp;=&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;nbsp;case to get (const +&amp;nbsp;&lt;i&gt;h&lt;/i&gt;)&amp;nbsp;in the product. This gives us an O(&lt;i&gt;n&lt;/i&gt; * log(&lt;i&gt;n&lt;/i&gt;) * num_bits) solution, which is &lt;a href=&quot;https://atcoder.jp/contests/agc075/submissions/72946723&quot;&gt;fast enough&lt;/a&gt;. You can check the linked solution for the implementation details.&lt;/div&gt;
&lt;p&gt;Thanks for reading, and check back soon for more catch-up summaries and EUC 2026 reports :)&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/7842441090758209580/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2026/02/a-shift-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/7842441090758209580'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/7842441090758209580'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2026/02/a-shift-week.html' title='A shift week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgutmgZ_hkIXecOuEOegJbiCuXLfotnmRWktl20Tn7_uvKt0_PSAvWCQsMjvEVDseqn9NP5GOi9CGtye6OIUANvDzqBgqdtkdl_85aVupIcsqu7OYm7KvSXGsBswMzVOY6Z3Gy-xzS_bS8XJ75Cre-rE8T9WdWh-DA_MoWgStzsEomgPxgbSE9MG3dz8K8=s72-w640-h146-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-6823952739170573362</id><published>2026-02-07T10:41:00.002+01:00</published><updated>2026-02-07T10:44:43.991+01:00</updated><title type='text'>EUC 2026 first day</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIS5Ae5iaBxbjaPwkG5xsTUeJVSy9vH8Rpo_I3O3xKjygwNgFNV5Y2-EeQAozsWKJhn0_rnS3kfCggff_N0NsNsPCKercvK81Dtzu9HvnM0GvCWT6mQseZa23NkFxXJ9BDRPy-gMYc7oOoMFfGjnYhm6NLspZo4JQBTFJj6SctYYJQ9c1LpV_6WcMtCG4/s4080/PXL_20260207_083336639.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIS5Ae5iaBxbjaPwkG5xsTUeJVSy9vH8Rpo_I3O3xKjygwNgFNV5Y2-EeQAozsWKJhn0_rnS3kfCggff_N0NsNsPCKercvK81Dtzu9HvnM0GvCWT6mQseZa23NkFxXJ9BDRPy-gMYc7oOoMFfGjnYhm6NLspZo4JQBTFJj6SctYYJQ9c1LpV_6WcMtCG4/w640-h482/PXL_20260207_083336639.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Yesterday I have arrived in Warsaw, which will host &lt;a href=&quot;https://euc.icpc.global/&quot;&gt;ICPC EUC&lt;/a&gt; 2026 this Sunday. As you can see on the left, Warsaw in Feburary (much like Wijk aan Zee in January) is very conductive for indoor activities, which is perfect to be able to truly focus on a programming competition.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I have arrived too late to get to the opening ceremony, but from the slides that were shared it seems that, among other things, Bill has announced the dates for the upcoming ICPC World Finals: November 15-20, 2026 in Dubai (which was already announced before), and September 14-19, 2027 in a yet undisclosed (but seemingly known to the ICPC organizers) location. The ICPC EUC 2027 location was announced last year to be Eindhoven, Netherlands.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipfEEhAt_kAITAmYpv1y6HqX6J370Uka5rZcogVxYt45WDti2gymRSOUXc19K97XXEmhkuzPtsthbkJOo1kQwzXmIR6qrwfAvUekFPmFGaPiqfILaPAcnZPg6lzBlqlYcODPB6CBBWKtWQyMu4qODe6UgaU58R8A1n0Ux-BSLkQb0FSsLcTvL0OsR6-JE/s4080/PXL_20260207_084849065.jpg&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipfEEhAt_kAITAmYpv1y6HqX6J370Uka5rZcogVxYt45WDti2gymRSOUXc19K97XXEmhkuzPtsthbkJOo1kQwzXmIR6qrwfAvUekFPmFGaPiqfILaPAcnZPg6lzBlqlYcODPB6CBBWKtWQyMu4qODe6UgaU58R8A1n0Ux-BSLkQb0FSsLcTvL0OsR6-JE/w640-h482/PXL_20260207_084849065.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;But for now the focus is on the upcoming championship, where 8 teams have already qualified for the Dubai World Finals from the various ERCs and are just competing for fun and glory, while ~8 more teams will qualify tomorrow. Best of luck!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/6823952739170573362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2026/02/euc-2026-first-day.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/6823952739170573362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/6823952739170573362'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2026/02/euc-2026-first-day.html' title='EUC 2026 first day'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIS5Ae5iaBxbjaPwkG5xsTUeJVSy9vH8Rpo_I3O3xKjygwNgFNV5Y2-EeQAozsWKJhn0_rnS3kfCggff_N0NsNsPCKercvK81Dtzu9HvnM0GvCWT6mQseZa23NkFxXJ9BDRPy-gMYc7oOoMFfGjnYhm6NLspZo4JQBTFJj6SctYYJQ9c1LpV_6WcMtCG4/s72-w640-h482-c/PXL_20260207_083336639.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-2903091923629800825</id><published>2025-12-24T15:11:00.000+01:00</published><updated>2025-12-24T15:11:39.677+01:00</updated><title type='text'>A digging week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh4eD-q1PWNSLgNdjUbadtTu4q2EZ8GrLqTUTuZE5sChd_lJ1Va0yhI7Z8Ue6yXM9LC6yaywbjiPpjT_NPWhhyIbcP2WvK4FS1WPdN76IyvxtXSLTFllyxNTqlfTHEkNWRiz0MLvREEcNdnjtcB-e2ePHZ6gdmIk4bvRm0MXwrhEXHr1czDYzgdnl1btA8&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;278&quot; data-original-width=&quot;1106&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh4eD-q1PWNSLgNdjUbadtTu4q2EZ8GrLqTUTuZE5sChd_lJ1Va0yhI7Z8Ue6yXM9LC6yaywbjiPpjT_NPWhhyIbcP2WvK4FS1WPdN76IyvxtXSLTFllyxNTqlfTHEkNWRiz0MLvREEcNdnjtcB-e2ePHZ6gdmIk4bvRm0MXwrhEXHr1czDYzgdnl1btA8=w640-h160&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Codeforces Global Round 31 last Friday wrapped up the 2025 Global Round series (&lt;a href=&quot;https://codeforces.com/contest/2180&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2180/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/149318&quot;&gt;analysis&lt;/a&gt;, &lt;a href=&quot;https://clist.by/standings/codeforces-global-rounds-2025-61841758/&quot;&gt;serie standings&lt;/a&gt; that use the &quot;sum all 3&quot; instead of the actual &quot;sum 2 best out of 3&quot; scoring system). I spent way too much time on implementation and debugging once again, solved A-F1 and then decided not to go for even more standard-ish implementation in F2 and instead tried to get H1 in the end, but could not actually solve it. ecnerwala had roughly the same amount of time as myself for H1 after solving A-G (even the &lt;a href=&quot;https://codeforces.com/blog/entry/149318?#comment-1333652&quot;&gt;strong version&lt;/a&gt; of G), and he did solve H1 as well to claim a clear first place. Well done!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhtiegBuDq35uukIMM78UOuqdiE6b4v5Bx0Tq90KF0xF2Kvst-3jfA2lbI96-0oVMuf1r7Z28W_3IbaC9b4Vszgwgw-oWIw1svc9dnbo5g4WqwiqRH8utZbYk_4iEqBrrSyxEa2LPaHDHI5PnNsww8Kg56SPjvuHNw31vhhDV5D3OaTVBkKpVnYBxzwhVs&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;237&quot; data-original-width=&quot;1430&quot; height=&quot;106&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhtiegBuDq35uukIMM78UOuqdiE6b4v5Bx0Tq90KF0xF2Kvst-3jfA2lbI96-0oVMuf1r7Z28W_3IbaC9b4Vszgwgw-oWIw1svc9dnbo5g4WqwiqRH8utZbYk_4iEqBrrSyxEa2LPaHDHI5PnNsww8Kg56SPjvuHNw31vhhDV5D3OaTVBkKpVnYBxzwhVs=w640-h106&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Meta Hacker Cup 2025 held its final, this time online, on Saturday (&lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/final-round/problems/A&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/final-round/scoreboard&quot;&gt;results&lt;/a&gt;, top 5 on the left). Gennady has won his 6th Hacker Cup, and it was not easy: he scored 44 out of his 71 points in the last hour, and Yui could still&amp;nbsp;have snatched the first place were her last-second submission in C1 correct. Congratulations to both! Looking at the scoreboard of this contest, it feels sad that all other contests have abandoned the system test concept and no longer reward writing good code and testing it before submission as much.&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhvaIemOqIZJo-MNcAiOXC7w506Cb0DQB6eSv5qWtmeWuj5tIk12q4u4neRVPK62qOOpWiY_XcAFI8JLpvmMpKM13uI3rq3NhV1FRsepZv2CovFuwZTMXEofo_r5ECWpTMG-0dO8q72YOy4WzzPMIGDn_8Be6RvNQtjhdzELtLLOsni5Mz_8oVPS8eLyxU&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;330&quot; data-original-width=&quot;830&quot; height=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhvaIemOqIZJo-MNcAiOXC7w506Cb0DQB6eSv5qWtmeWuj5tIk12q4u4neRVPK62qOOpWiY_XcAFI8JLpvmMpKM13uI3rq3NhV1FRsepZv2CovFuwZTMXEofo_r5ECWpTMG-0dO8q72YOy4WzzPMIGDn_8Be6RvNQtjhdzELtLLOsni5Mz_8oVPS8eLyxU=w640-h254&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;AtCoder is wrapping up the year with two last chances to qualify for AWTF 2026, the first of which was Grand Contest 075 (&lt;a href=&quot;https://atcoder.jp/contests/agc075/tasks&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://atcoder.jp/contests/agc075/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://atcoder.jp/contests/agc075/editorial&quot;&gt;analysis&lt;/a&gt;, &lt;a href=&quot;https://clist.by/standings/atcoder-race-ranking-2025-algorithm-57173720/&quot;&gt;serie standings&lt;/a&gt;). In problem A, I was looking for an algorithmic solution, trying hard to find some sort of knapsack subproblem with slowly increasing weights that can be solved by greedy or backtracking. However, it seems that this was a dead end, and one had to pull the main idea out of thin air, or to print the answers for small &lt;i&gt;n&lt;/i&gt; and generalize.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I&#39;ve then tried to solve problems B and C, but there I actually had an opposite issue: I was digging in the right direction (maintaining a piecewise-constant rolling window of size &lt;i&gt;y&lt;/i&gt; in B, going in increasing order of &lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; and checking how much we can deviate from the sorted order of&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;in C), but at some point I stopped digging, with the justification that in an AGC problem I should look for a beautiful alternative approach instead, which I could not find. After reading the editorial it turned out that the missing piece was more digging :)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Luckily, in problem D the required digging was not very deep, and I managed to get a non-zero score with a whopping 2 minutes remaining in the round. This did not get me any tour points, but I guess there is still an imaginary chance to qualify if I win the upcoming AGC 076. That is not going to happen, of course :)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;tourist did his share of digging faster than others, but as his AWTF qualification was set in stone anyway, these results might be celebrated more by Kevin090228 who has likely guaranteed his AWTF qualification with this second place, and&amp;nbsp;f3e6g4 who has jumped into the magical top 12 for now. Congratulations to all three!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let me highlight &lt;a href=&quot;https://atcoder.jp/contests/agc075/tasks/agc075_c&quot;&gt;problem C&lt;/a&gt; from this round, at a risk of not being able to fully describe a solution next week: you are given two sequences of integers&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;and&amp;nbsp;&lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;of the same length &lt;i&gt;n&lt;/i&gt; up to 2*10&lt;sup&gt;5&lt;/sup&gt;, 1&amp;lt;=&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=10&lt;sup&gt;9&lt;/sup&gt;, 0&amp;lt;=&lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=30. We will permute the sequence&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;arbitrarily, and then compute sum(&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;gt;&amp;gt;&lt;i&gt;b&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;), where &amp;gt;&amp;gt; denotes the bitwise shift right. How many of the &lt;i&gt;n&lt;/i&gt;! permutations yield the smallest possible value of that sum? You need to print the answer modulo&amp;nbsp;998244353.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks for reading, and check back next week.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/2903091923629800825/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/12/a-digging-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/2903091923629800825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/2903091923629800825'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/12/a-digging-week.html' title='A digging week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEh4eD-q1PWNSLgNdjUbadtTu4q2EZ8GrLqTUTuZE5sChd_lJ1Va0yhI7Z8Ue6yXM9LC6yaywbjiPpjT_NPWhhyIbcP2WvK4FS1WPdN76IyvxtXSLTFllyxNTqlfTHEkNWRiz0MLvREEcNdnjtcB-e2ePHZ6gdmIk4bvRm0MXwrhEXHr1czDYzgdnl1btA8=s72-w640-h160-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-7334555203577507802</id><published>2025-12-15T11:00:00.003+01:00</published><updated>2025-12-15T12:17:19.940+01:00</updated><title type='text'>A 13-10 week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjbgDcE_yq7zjIrluu9nuPLneqfiX9op3BMHMW_BDZBcwedLShhOMx79dbsKoBUJdTG_b_msWtKiFyOZNf9t9dKsyyIPf3lVsT-7QV3UHMlU0-q_WnNPlC_BmTN0A-EXn7UjodzonPWgO2It44xZEdXurW7BSl9M8Ng9jDN0EaAixsdmYneBZiPt3_6Ws4&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;238&quot; data-original-width=&quot;1116&quot; height=&quot;136&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjbgDcE_yq7zjIrluu9nuPLneqfiX9op3BMHMW_BDZBcwedLShhOMx79dbsKoBUJdTG_b_msWtKiFyOZNf9t9dKsyyIPf3lVsT-7QV3UHMlU0-q_WnNPlC_BmTN0A-EXn7UjodzonPWgO2It44xZEdXurW7BSl9M8Ng9jDN0EaAixsdmYneBZiPt3_6Ws4=w640-h136&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The Universal Cup Grand Prix of Jinan was the only round of last week (&lt;a href=&quot;https://contest.ucup.ac/contest/2693&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2693&quot;&gt;results&lt;/a&gt;, top 5 on the left). This season is turning out to be the most one-sided to date, with team USA1, which &lt;a href=&quot;https://clist.by/standings/?search=universal+cup+%26%26+rating&quot;&gt;won all previous seasons&lt;/a&gt;, winning 8 out of the first 9 Grand Prix. This particular contest was very one-sided as well, with USA1 winning 13 problems to 10, with more than an hour to spare. Well done!&lt;p&gt;&lt;/p&gt;&lt;div&gt;One slightly disappointing thing about the Universal Cup is that the problem discussions happen on Discord, so they are not publicly searchable/discoverable, which I think is quite bad for the overall programming contest ecosystem: most people won&#39;t see those discussions, so they are not inspired to solve and create new problems by seeing the greats share their passion for solving, not to mention the (likely inevitable) day in the far future where the Discord server no longer works, and the information is gone or at least no longer discoverable via old links. I&#39;m wondering if the Universal Cup team has considered holding the discussions on Codeforces, or creating their own public forum instead, or maybe making the Discord discussions visible via a public/indexed page?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7KrGA-xw3yaF0d45XEyLbJIdlE_TUNcPOwv8gjAc544JQ0qAbK14-tGf1KnuWde6CK3OhcceD4w0pYy7y13S_VNvDEP3tod_QAPoOEiAQPSNNSexV03ikIvth73RX2LDqfe0b6z1yh_b8JaxYZluo2ZThQy6UrWSlWKSlv6cY-czCu2_RtYBMezVAaZY/s4080/PXL_20241005_132910677.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7KrGA-xw3yaF0d45XEyLbJIdlE_TUNcPOwv8gjAc544JQ0qAbK14-tGf1KnuWde6CK3OhcceD4w0pYy7y13S_VNvDEP3tod_QAPoOEiAQPSNNSexV03ikIvth73RX2LDqfe0b6z1yh_b8JaxYZluo2ZThQy6UrWSlWKSlv6cY-czCu2_RtYBMezVAaZY/w640-h482/PXL_20241005_132910677.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In &lt;a href=&quot;https://blog.mitrichev.ch/2025/12/a-winter-week.html&quot;&gt;my previous summary&lt;/a&gt;, I have mentioned&amp;nbsp;&lt;a href=&quot;https://codeforces.com/gym/106249/problem/A&quot;&gt;a M(IT)^2 problem&lt;/a&gt;: you are given a string of length &amp;lt;=10&lt;sup&gt;5&lt;/sup&gt;. You can replace any occurrence of &lt;span style=&quot;font-family: courier;&quot;&gt;MIT&lt;/span&gt; with &lt;span style=&quot;font-family: courier;&quot;&gt;TIM&lt;/span&gt; and vice versa, and do that as many times as you want. What is the maximum number of occurrences of &lt;span style=&quot;font-family: courier;&quot;&gt;MITIT&lt;/span&gt; you can get?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If we look only at every second letter in the string, then what happens is that we swap adjacent &lt;span style=&quot;font-family: courier;&quot;&gt;M&lt;/span&gt; and &lt;span style=&quot;font-family: courier;&quot;&gt;T&lt;/span&gt; in that half-string, but this is only possible if the other half-string has an &lt;span style=&quot;font-family: courier;&quot;&gt;I&lt;/span&gt; in the right place. Since the &lt;span style=&quot;font-family: courier;&quot;&gt;I&lt;/span&gt;s never change, this condition is static. So what actually happens is we find the substrings of the original string that satisfy the following criteria:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;It has &lt;span style=&quot;font-family: courier;&quot;&gt;M&lt;/span&gt;/&lt;span style=&quot;font-family: courier;&quot;&gt;T&lt;/span&gt; on positions of one parity.&lt;/li&gt;&lt;li&gt;It has &lt;span style=&quot;font-family: courier;&quot;&gt;I&lt;/span&gt; on positions of the other parity.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Now consider all maximal substrings (ones that cannot be extended) with this property:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;They won&#39;t overlap so they can be handled independently, since if two such strings overlap then their union is also such string.&lt;/li&gt;&lt;li&gt;Each occurrence of MITIT will always be entirely within one of them.&lt;/li&gt;&lt;li&gt;We can arbitrarily rearrange Ms and Ts within each of them, since adjacent swaps can produce any permutation.&lt;/li&gt;&lt;li&gt;Therefore the maximum number of occurrences of MITIT is min(&lt;i&gt;m&lt;/i&gt;, &lt;i&gt;t&lt;/i&gt;/2) where &lt;i&gt;m&lt;/i&gt; is the number of Ms and &lt;i&gt;t&lt;/i&gt; is the number ot Ts.&lt;/li&gt;&lt;/ul&gt;Finally, we need to be able to implement this cleanly. I suggest to have an outside loop for the parity (whether odd or even positions have&amp;nbsp;&lt;span style=&quot;font-family: courier;&quot;&gt;I&lt;/span&gt;s), then within this loop every position either has a good letter or not, so we can iterate over the string and maintain the values of &lt;i&gt;m&lt;/i&gt; and &lt;i&gt;t&lt;/i&gt; for the running substring, resetting both to zero when we see a bad letter for a certain position. Something like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;int res = 0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;for (int p = 0; p &amp;lt; 2; ++p) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; int m = 0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; int t = 0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; for (int i = 0; i &amp;lt;= s.size(); ++i) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; &amp;nbsp; bool ok = i &amp;lt; s.size() &amp;amp;&amp;amp; ((s[i] == &#39;I&#39;) ^ ((i + p) % 2));&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; &amp;nbsp; if (ok) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if (s[i] == &#39;M&#39;) ++m;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if (s[i] == &#39;T&#39;) ++t;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; &amp;nbsp; } else {&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; res += min(m, t / 2);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; m = 0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; t = 0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks for reading, and check back next week!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/7334555203577507802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/12/a-13-10-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/7334555203577507802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/7334555203577507802'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/12/a-13-10-week.html' title='A 13-10 week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjbgDcE_yq7zjIrluu9nuPLneqfiX9op3BMHMW_BDZBcwedLShhOMx79dbsKoBUJdTG_b_msWtKiFyOZNf9t9dKsyyIPf3lVsT-7QV3UHMlU0-q_WnNPlC_BmTN0A-EXn7UjodzonPWgO2It44xZEdXurW7BSl9M8Ng9jDN0EaAixsdmYneBZiPt3_6Ws4=s72-w640-h136-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-333863948986048699</id><published>2025-12-12T20:51:00.000+01:00</published><updated>2025-12-12T20:51:05.588+01:00</updated><title type='text'>A winter week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjJrEkaX79lXnDrQuFlHfJSPCxjOWS5D3yKMeJU9Nuq6NL7XgnLmlqoCCNsgiTQBidxlUIKBWBNxUf4fjM3ASKtOrvXJLrpjPvFnsdNClodLLrnx6NF99pe3UOxiayGaQQJDxML9JqoKX_dgQT_pkl2qt9kpVwSiuQAKaBGylpZvFJw26FnedxZtIBy7Ig&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;417&quot; data-original-width=&quot;1249&quot; height=&quot;214&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjJrEkaX79lXnDrQuFlHfJSPCxjOWS5D3yKMeJU9Nuq6NL7XgnLmlqoCCNsgiTQBidxlUIKBWBNxUf4fjM3ASKtOrvXJLrpjPvFnsdNClodLLrnx6NF99pe3UOxiayGaQQJDxML9JqoKX_dgQT_pkl2qt9kpVwSiuQAKaBGylpZvFJw26FnedxZtIBy7Ig=w640-h214&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The last weekend was packed with contests. First off, the Yandex Cup 2025 onsite final took place in Istanbul early on Saturday (&lt;a href=&quot;https://new.contest.yandex.com/contests/86430/leaderboard?contestId=86430&amp;amp;page=1&amp;amp;pageSize=100&quot;&gt;results&lt;/a&gt;, top 5 on the left). The usual suspects topped the scoreboard, and Kevin got the highest score in each problem and earned the well-deserved first place. Congratulations!&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This was already &lt;a href=&quot;https://cphof.org/contests&quot;&gt;the 10th cphof-worthy contest&lt;/a&gt; of 2025, and with the addition of the &lt;a href=&quot;https://cphof.org/advanced/fhc/2025&quot;&gt;upcoming Hacker Cup&lt;/a&gt; and the completed without published results &lt;a href=&quot;https://www.topcoder.com/marathon-match-tournament&quot;&gt;TopCoder Marathon Match Tournament&lt;/a&gt; (yes, TopCoder is still around! But does anybody know what happened to the results?) it could be 12. That is a big improvement over the recent years, and the overall record of 17 per year in 2016 does not look too far away. Huge thanks to all organizers, and I&#39;m looking forward to the 2026 editions!&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjtVUIB70kcYJS93C8Yxutnj2JStHjewqQjbp41KD8rKXo8a2fvEkpSpZI9-htVUNOq-OZ63xbKzHsos36k50KDq-wfFRti5I4rLrX16mCFBso-dc4C9fh0qxz9aVYWh1hJwIGqsqgCz5WyKkyaOyUNYitOq0Bw0KnDarW9dfwwvXwzkOoN7ckNBXAWReU&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;276&quot; data-original-width=&quot;1108&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjtVUIB70kcYJS93C8Yxutnj2JStHjewqQjbp41KD8rKXo8a2fvEkpSpZI9-htVUNOq-OZ63xbKzHsos36k50KDq-wfFRti5I4rLrX16mCFBso-dc4C9fh0qxz9aVYWh1hJwIGqsqgCz5WyKkyaOyUNYitOq0Bw0KnDarW9dfwwvXwzkOoN7ckNBXAWReU=w640-h160&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Codeforces Round 1069, which reused some of the problems of the Yandex final, took place in parallel (&lt;a href=&quot;https://codeforces.com/contest/2174&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2174/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/149003&quot;&gt;analysis&lt;/a&gt;). &lt;a href=&quot;https://codeforces.com/blog/entry/118803&quot;&gt;A Kevin&lt;/a&gt;&amp;nbsp;won here as well, solving problem D with just 6 minutes remaining in the round. Kudos for the perseverance!&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgo2aKlqFX4fIahd-h_KfNMw0QsJjaRprXgX9gf_tSCEh_J449QzivDKfEpTB61BeIlnn8wRd8_KrzIhzJlRrPpMZMOrtOxbbfyfKtcsBr7uBUsJBW7DQrmjeoTK3i0FyhkGgvYmBI_v00cJaPvhANg7z73-6d_yVnSzdld1kTpyxIgzjs2MPV_a0CEvCc&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;236&quot; data-original-width=&quot;1079&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgo2aKlqFX4fIahd-h_KfNMw0QsJjaRprXgX9gf_tSCEh_J449QzivDKfEpTB61BeIlnn8wRd8_KrzIhzJlRrPpMZMOrtOxbbfyfKtcsBr7uBUsJBW7DQrmjeoTK3i0FyhkGgvYmBI_v00cJaPvhANg7z73-6d_yVnSzdld1kTpyxIgzjs2MPV_a0CEvCc=w640-h140&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The Universal Cup Grand Prix of Poland also took place on Saturday (&lt;a href=&quot;https://contest.ucup.ac/contest/2668&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2668&quot;&gt;results&lt;/a&gt;, top 5 on the left). The first Kevin, together with his teammates, needed less than half of the contest to wrap things up, almost 90 minutes faster than everybody else. The closest pursuers were the other veteran teams Almost Retired Dandelion and Amstelpark, and I am of course partial to seeing veteran teams perform well. Congratulations!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjcnZGR0G1HUq_uB1LPFRo7jNo5Fjt9VE6Iqr9_8q4WQB5cD6BufspUS9G_ch41EddifJJu5MCX-BVRCttTOH4OMnIAl2ksCYFgtCydfADzySCTSoundEVOByAHx6Navutls4FpGxauTMGKdg2YGIqgxfweQ45_pNUXWgdrdPd6j6GZKoFHD5Ytj6FU0Z4&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;452&quot; data-original-width=&quot;1088&quot; height=&quot;266&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjcnZGR0G1HUq_uB1LPFRo7jNo5Fjt9VE6Iqr9_8q4WQB5cD6BufspUS9G_ch41EddifJJu5MCX-BVRCttTOH4OMnIAl2ksCYFgtCydfADzySCTSoundEVOByAHx6Navutls4FpGxauTMGKdg2YGIqgxfweQ45_pNUXWgdrdPd6j6GZKoFHD5Ytj6FU0Z4=w640-h266&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The M(IT)^2 25-26 Winter Contest followed on Sunday, starting with the Individual Round (&lt;a href=&quot;https://codeforces.com/gym/106249&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://mitit.org/Contest/ViewScoreboard/advanced-indiv-25-26&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/gym/106250/attachments/download/34709/MITIT_Winter_2025_2026_Team_Editorials-1.pdf&quot;&gt;analysis&lt;/a&gt;). The second Kevin came out ahead this time, but he had to wait anxiously for quite some time since Gennady had a big penalty time advantage after the first four problems, and therefore could afford to solve the fifth problem twenty minutes later but still win. This did not happen, so congratulations on the victory!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The &lt;a href=&quot;https://codeforces.com/gym/106249/problem/A&quot;&gt;easiest problem&lt;/a&gt; turned out to be (relatively) challenging for me, as I used 12 minutes to get it right while some others needed only 3. It went like this: you are given a string of length &amp;lt;=10&lt;sup&gt;5&lt;/sup&gt;. You can replace any occurrence of &lt;span style=&quot;font-family: courier;&quot;&gt;MIT&lt;/span&gt; with &lt;span style=&quot;font-family: courier;&quot;&gt;TIM&lt;/span&gt; and vice versa, and do that as many times as you want. What is the maximum number of occurrences of &lt;span style=&quot;font-family: courier;&quot;&gt;MITIT&lt;/span&gt; you can get? Can you see how to solve and implement this without too much casework?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhml1y8ZtIMw9RrOGrPOg-a_oOhBekcZwEpyrfpVzv3qMV-AJVkXtD77YmKZvQ2vXSpgXWc2L2EkFiqgamb1lNLvhcshh-XN8pI96F8ttis7YHwl61YYRQzMx67CHEY0Hs_3jyCjPjHd8MDhUAAlvuBkmlT0M8Vw8ccClYNrlj4y0i5rr-RtAGWA35rXSg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;450&quot; data-original-width=&quot;1492&quot; height=&quot;194&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhml1y8ZtIMw9RrOGrPOg-a_oOhBekcZwEpyrfpVzv3qMV-AJVkXtD77YmKZvQ2vXSpgXWc2L2EkFiqgamb1lNLvhcshh-XN8pI96F8ttis7YHwl61YYRQzMx67CHEY0Hs_3jyCjPjHd8MDhUAAlvuBkmlT0M8Vw8ccClYNrlj4y0i5rr-RtAGWA35rXSg=w640-h194&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The Team Round followed a few hours later (&lt;a href=&quot;https://codeforces.com/gym/106249&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://mitit.org/Contest/ViewScoreboard/advanced-team-25-26&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/gym/106250/attachments/download/34709/MITIT_Winter_2025_2026_Team_Editorials-1.pdf&quot;&gt;analysis&lt;/a&gt;, &lt;a href=&quot;https://www.youtube.com/live/Mi6RqGP7yJM&quot;&gt;award ceremony stream&lt;/a&gt;). Finally, no Kevins in the first place: team T1 had&amp;nbsp;&lt;a href=&quot;https://cphof.org/profile/topcoder:gs14004&quot;&gt;Jaehyun&lt;/a&gt;, &lt;a href=&quot;https://cphof.org/profile/topcoder:tourist&quot;&gt;Gennady&lt;/a&gt; and &lt;a href=&quot;https://cphof.org/profile/topcoder:ainta&quot;&gt;Sunghyeon&lt;/a&gt;&amp;nbsp;instead. Congratulations!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks for reading, and check back next week!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/333863948986048699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/12/a-winter-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/333863948986048699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/333863948986048699'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/12/a-winter-week.html' title='A winter week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjJrEkaX79lXnDrQuFlHfJSPCxjOWS5D3yKMeJU9Nuq6NL7XgnLmlqoCCNsgiTQBidxlUIKBWBNxUf4fjM3ASKtOrvXJLrpjPvFnsdNClodLLrnx6NF99pe3UOxiayGaQQJDxML9JqoKX_dgQT_pkl2qt9kpVwSiuQAKaBGylpZvFJw26FnedxZtIBy7Ig=s72-w640-h214-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-1344709289322811026</id><published>2025-12-01T10:52:00.003+01:00</published><updated>2025-12-01T10:53:27.482+01:00</updated><title type='text'>A 29 week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgWab8r7egB5cJZCbY_7jr3grwLmhh9yT3Ved1JlvRaC1O3xFRpYSUhKUtYcDnJ10oJZqb0VMtkN4AO7fd0Z5-A7Sy9F73n68PLTAhmencscb2N0X_AztVI6K6QKuYVe5_R1kEOGiyWqlhoB4zL3CqgABJn9k34Lhc-etKWDdU8jGSuArpeAIfNEbPwz3M&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;232&quot; data-original-width=&quot;1396&quot; height=&quot;106&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgWab8r7egB5cJZCbY_7jr3grwLmhh9yT3Ved1JlvRaC1O3xFRpYSUhKUtYcDnJ10oJZqb0VMtkN4AO7fd0Z5-A7Sy9F73n68PLTAhmencscb2N0X_AztVI6K6QKuYVe5_R1kEOGiyWqlhoB4zL3CqgABJn9k34Lhc-etKWDdU8jGSuArpeAIfNEbPwz3M=w640-h106&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Meta Hacker Cup 2025 Round 3 on Saturday narrowed the field down to the 25 finalists (&lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-3/problems/A&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-3/scoreboard&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://youtu.be/evt-Q_gilrI&quot;&gt;my screencast&lt;/a&gt;). After solving B relatively quickly, I got stuck &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-3/problems/A&quot;&gt;on A&lt;/a&gt; for about 50 minutes. The overall solution plan was relatively clear&amp;nbsp;— &lt;i&gt;k&lt;/i&gt;=2 is a special case, in all other cases we can achieve the minimum amount derived from the area by solving greedily with some small backtracking or heuristic to deal with the diagonal. However, I could not figure out that heuristic, neither on paper nor by trying things on the computer. When I decided to give up and switch to other problems, a lot of time had already been wasted.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I&#39;ve then solved D and C relatively quickly again, and also figured out the overall plan &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-3/problems/E&quot;&gt;for E&lt;/a&gt; on paper: we just need to put two 1s at the end and solve recursively, and to achieve that we can first move two 1s into one of the last 6 positions by big swaps that essentially swap the first and second halves of some suffix, and then do some casework to move them to exactly the last 2 positions. However, I got bogged down in that casework, and only a few minutes before the end I realized that I can just implement any bfs, dfs, or bruteforce to solve the problem for &lt;i&gt;n&lt;/i&gt;=3 without manual casework, and it was a bit too late, I have finished debugging only by using 5-10 additional minutes after the end of the round.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It was therefore only place 29 for me, and top 25 qualify for the final round :( It is an improvement over place 42 &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2024/round-3/scoreboard&quot;&gt;last year&lt;/a&gt;, and unlike the AtCoder WTF qualification, here I felt that the qualification was well within reach, and I had only myself to blame for wasting too much time on A. So, I have big hopes to qualify next year!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What is more disappointing (but maybe expected?) is that I did well on quite standard problems B, C and D that were mostly about quick implementation for me, but poorly on the heuristic/ad-hoc problems A and E. Those problems were set nicely in such a way that many approaches work, without squeezing the constraints so much that only a specific heuristic is required, and I enjoy both solving and setting such problems a lot. I think such problems reward the will and ability to experiment using a computer and practical problem solving skills, which are quite general qualities useful outside of the programming competition world. So please do try to solve problems A and E for practice if the above did not spoil them too much, I think you will find it quite enjoyable!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As usual, the strategy does not matter as much if you can just solve everything :) Congratulations to &lt;a href=&quot;https://cphof.org/profile/topcoder:lyrically&quot;&gt;Yui&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;https://cphof.org/profile/topcoder:tourist&quot;&gt;Gennady&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href=&quot;https://cphof.org/profile/topcoder:ksun48&quot;&gt;Kevin&lt;/a&gt;&amp;nbsp;on the great performance!&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjZYsAmCjm9iV9C9t-GIRrFigPx7dUnhDPWocZi0CFg1hAljsmO3dR6R4RDAZXZ57ByQh6V4bOQFgI4uERTF2mJM0yjJ8tlGLoLUJIxvC0wQdYXhRWGsF-YnSgXKRI_R7TU7RXzsnPG7PtwfgLS7THoDxodUBU99FG3Q9WfFkJ9P0TWnY2xA5hUheWGI88&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;240&quot; data-original-width=&quot;1073&quot; height=&quot;144&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjZYsAmCjm9iV9C9t-GIRrFigPx7dUnhDPWocZi0CFg1hAljsmO3dR6R4RDAZXZ57ByQh6V4bOQFgI4uERTF2mJM0yjJ8tlGLoLUJIxvC0wQdYXhRWGsF-YnSgXKRI_R7TU7RXzsnPG7PtwfgLS7THoDxodUBU99FG3Q9WfFkJ9P0TWnY2xA5hUheWGI88=w640-h144&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The 4th Universal Cup Stage 7:&amp;nbsp;Grand Prix of Zhengzhou also took place on Saturday (&lt;a href=&quot;https://contest.ucup.ac/contest/2661&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2661&quot;&gt;results&lt;/a&gt;, top 5 on the left). &lt;a href=&quot;https://cphof.org/profile/topcoder:tourist&quot;&gt;Gennady&lt;/a&gt; and &lt;a href=&quot;https://cphof.org/profile/topcoder:ksun48&quot;&gt;Kevin&lt;/a&gt; showed up again to claim the first place together with &lt;a href=&quot;https://cphof.org/profile/topcoder:ecnerwal&quot;&gt;Andrew&lt;/a&gt;, even though &lt;a href=&quot;https://cphof.org/profile/topcoder:xudyh&quot;&gt;Yuhao&lt;/a&gt;, &lt;a href=&quot;https://cphof.org/profile/topcoder:jiangly&quot;&gt;Lingyu&lt;/a&gt; and &lt;a href=&quot;https://cphof.org/profile/codeforces:Kevin114514&quot;&gt;Qiwen&lt;/a&gt; (with an average Codeforces rating even higher than USA1!) put up a good fight and were trying to solve L and overtake them right until the end. Well done to both teams!&lt;p&gt;&lt;/p&gt;&lt;div&gt;Thanks for reading, and check back next week!&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/1344709289322811026/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/12/a-29-week.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/1344709289322811026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/1344709289322811026'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/12/a-29-week.html' title='A 29 week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgWab8r7egB5cJZCbY_7jr3grwLmhh9yT3Ved1JlvRaC1O3xFRpYSUhKUtYcDnJ10oJZqb0VMtkN4AO7fd0Z5-A7Sy9F73n68PLTAhmencscb2N0X_AztVI6K6QKuYVe5_R1kEOGiyWqlhoB4zL3CqgABJn9k34Lhc-etKWDdU8jGSuArpeAIfNEbPwz3M=s72-w640-h106-c" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-523920488234544496</id><published>2025-11-27T21:04:00.000+01:00</published><updated>2025-11-27T21:04:12.807+01:00</updated><title type='text'>A double prix week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhkdJbQCi3Ai2XhbYYooITndwPgE07N1jQNydUcDKVj4Osy1e5caqtpsbUIjeZRNY3_Sx3EJBvpJSLOgW-saPFaEHrD_EnW0Y-kwugzeqmTyLdqfs2LZcxXyfSXqvIxIwbGINQNWPIHtTuvN616cIveFTIY9PLYVbk0o5I3UyZqcdZ3KxXsXcnXv7LXSGc&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;226&quot; data-original-width=&quot;1084&quot; height=&quot;134&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhkdJbQCi3Ai2XhbYYooITndwPgE07N1jQNydUcDKVj4Osy1e5caqtpsbUIjeZRNY3_Sx3EJBvpJSLOgW-saPFaEHrD_EnW0Y-kwugzeqmTyLdqfs2LZcxXyfSXqvIxIwbGINQNWPIHtTuvN616cIveFTIY9PLYVbk0o5I3UyZqcdZ3KxXsXcnXv7LXSGc=w640-h134&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Before I cover the last week, I need to mention the 4th Universal Cup Stage 5:&amp;nbsp;Nanjing, which happened the week before and which I forgot to cover (&lt;a href=&quot;https://contest.ucup.ac/contest/2581&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2581&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://ucup.ac/tutorials/tutorials-4-05-zh.pdf&quot;&gt;analysis in Chinese&lt;/a&gt;). Even having only 2 out of 3 teammates did not stop team USA1 from winning by a whole problem. Congratulations!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhibdsQknZHErmtQxqVKZObUTPhAZlMStNxc9C-2Qv0FnEq38SMniO-sBrI6H9yQEE6HtUJoXvwCZnul8ijDkbRG8p_f9FugMkVcb2u_WtRMZTXpJsI2BHw-dVqATFCZrC9DxROpL8yqyHoSDSuEM39ggDbl_lz0q8BhVz7LDUOLbK3s2WnM1fxNdGT4bU&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;233&quot; data-original-width=&quot;1127&quot; height=&quot;132&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhibdsQknZHErmtQxqVKZObUTPhAZlMStNxc9C-2Qv0FnEq38SMniO-sBrI6H9yQEE6HtUJoXvwCZnul8ijDkbRG8p_f9FugMkVcb2u_WtRMZTXpJsI2BHw-dVqATFCZrC9DxROpL8yqyHoSDSuEM39ggDbl_lz0q8BhVz7LDUOLbK3s2WnM1fxNdGT4bU=w640-h132&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The Universal Cup can&#39;t stick to the plan of having rounds only every other week, so Stage 6:&amp;nbsp;Shenyang took place last week (&lt;a href=&quot;https://contest.ucup.ac/contest/2641&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2641&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://ucup.ac/tutorials/tutorials-4-06-zh.pdf&quot;&gt;analysis in Chinese&lt;/a&gt;). The first two places look suspiciously similar to the previous round, but for the veteran teams Polish Mafia and Almost Retired Dandelion who also solved everything this was the best result of the season. Well done!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgTb9FJCw7PJLuuxo6WKiaAWZ4e_D8Iw74xWLGLpT2oOW690W4lopXbDtXeWDyqONS54dvyuMa89NVsEbdmo4M-_d4gDFeTwagsMZTk7RSwLo8uhRcWcTsyvcAaB6bXAiJvrpEDtoWKcXoPjVVyb4cav2LJs4TuwAneyj1rNCNDCv0_A5aX3twdAGRHK30&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;278&quot; data-original-width=&quot;1104&quot; height=&quot;162&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgTb9FJCw7PJLuuxo6WKiaAWZ4e_D8Iw74xWLGLpT2oOW690W4lopXbDtXeWDyqONS54dvyuMa89NVsEbdmo4M-_d4gDFeTwagsMZTk7RSwLo8uhRcWcTsyvcAaB6bXAiJvrpEDtoWKcXoPjVVyb4cav2LJs4TuwAneyj1rNCNDCv0_A5aX3twdAGRHK30=w640-h162&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Codeforces Round 1066 wrapped up the week (&lt;a href=&quot;https://codeforces.com/contest/2157&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2157/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/148631&quot;&gt;analysis&lt;/a&gt;). Some of the Universal Cup stars were also strong this time, but they were complemented in the top 5 by jiangbowen and PEIMUDA who were not at the very top in the team rounds. Congratulations on the nice individual performance!&lt;p&gt;&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back next week for a more meaningful summary!&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/523920488234544496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/11/a-double-prix-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/523920488234544496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/523920488234544496'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/11/a-double-prix-week.html' title='A double prix week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhkdJbQCi3Ai2XhbYYooITndwPgE07N1jQNydUcDKVj4Osy1e5caqtpsbUIjeZRNY3_Sx3EJBvpJSLOgW-saPFaEHrD_EnW0Y-kwugzeqmTyLdqfs2LZcxXyfSXqvIxIwbGINQNWPIHtTuvN616cIveFTIY9PLYVbk0o5I3UyZqcdZ3KxXsXcnXv7LXSGc=s72-w640-h134-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-4274146025016212539</id><published>2025-11-27T00:04:00.000+01:00</published><updated>2025-11-27T00:04:23.264+01:00</updated><title type='text'>An array week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh0d30d9CisSw6QkvUQSCYMsFKAh_Lsn2Qnuu_6fJtA-l4j8XAqvW7T-zENr82ARvKJeeA3J3ylP-T9TR2Ky9OMV0uJuZixB1ZCaVOEz8KyDjJAK2JsNpo5bxBj8kbnDgYdUEfR65FLoSwg3V5rJHECI698PIfWNT-dsYyiKi4HG02vrMB1qVXVCnNH7Io&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;239&quot; data-original-width=&quot;1193&quot; height=&quot;128&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh0d30d9CisSw6QkvUQSCYMsFKAh_Lsn2Qnuu_6fJtA-l4j8XAqvW7T-zENr82ARvKJeeA3J3ylP-T9TR2Ky9OMV0uJuZixB1ZCaVOEz8KyDjJAK2JsNpo5bxBj8kbnDgYdUEfR65FLoSwg3V5rJHECI698PIfWNT-dsYyiKi4HG02vrMB1qVXVCnNH7Io=w640-h128&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Meta Hacker Cup 2025 Round 2 was the first event of the Nov 10&amp;nbsp;— Nov 16 week (&lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-2/problems/B&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-2/scoreboard&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-2/solutions&quot;&gt;analysis&lt;/a&gt;, &lt;a href=&quot;https://youtu.be/-CSci_UpKQU&quot;&gt;my screencast&lt;/a&gt;). Once again getting the problems right was more important than solving them fast, but it is still more impressive to do both at the same time. Congratulations to Benq and Um_nik who got quite a margin in penalty time compared to the rest of the full scorers!&lt;p&gt;&lt;/p&gt;&lt;p&gt;In &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-2/problems/D&quot;&gt;problem D&lt;/a&gt;, my solution (like all other solutions) was exponential in &lt;i&gt;k&lt;/i&gt;. When I ran it on the validation input, it turned out that one case with &lt;i&gt;k&lt;/i&gt;=25 (the maximum) takes about 30 seconds, so I was not sure if 80 such cases would run in time, even with the multithreaded template. But then I realized that the exponential part of the solution depends only on &lt;i&gt;k&lt;/i&gt;, so we can precompute it once for all possible values of &lt;i&gt;k&lt;/i&gt;, and then solve the 80 testcases in polynomial time. The precomputation only took about 40 seconds for all values of &lt;i&gt;k&lt;/i&gt; (since the running time is exponential, &lt;i&gt;k&lt;/i&gt;=24 is already much faster than &lt;i&gt;k&lt;/i&gt;=25 and so on), and I was able to comfortably submit within the 6 minute window.&lt;/p&gt;&lt;p&gt;What I did not realize is that even if the precomputation took 10 minutes, I would still be able to submit, because one can run the precomputation before downloading the input! And unlike regular contests where the result of the precomputation in such cases must fit into the source limit, here we can just keep it in memory (in case we trust that the program will not crash on the first run) or save it to disk. I never had to do something like this in the Hacker Cup, but will definitely keep this trick in mind!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiGWsXvhs_jdqo0hnhD6VNq2yC3IJcl9iXEppqolItWI2ffslKYPglmwPCxtgzrKyBOr02Jud28uDFzvCGB6uSMsqxQbPWjPSxS_mVKcrbNarnhRa8Yaxsp5NHKvGIqYbIcQZwpCwOzPrMPpwL5EhZYP6QHV0x4W0Pce__pjRtYmn7TLHMCRKclq-g4Tik&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;276&quot; data-original-width=&quot;1103&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiGWsXvhs_jdqo0hnhD6VNq2yC3IJcl9iXEppqolItWI2ffslKYPglmwPCxtgzrKyBOr02Jud28uDFzvCGB6uSMsqxQbPWjPSxS_mVKcrbNarnhRa8Yaxsp5NHKvGIqYbIcQZwpCwOzPrMPpwL5EhZYP6QHV0x4W0Pce__pjRtYmn7TLHMCRKclq-g4Tik=w640-h160&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Codeforces Round 1064 wrapped up the week on Sunday (&lt;a href=&quot;https://codeforces.com/contest/2165&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2165/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/148452&quot;&gt;analysis&lt;/a&gt;). maroonrk was done with 42 minutes to go, but only&amp;nbsp;JDScript0117 was able to join him with 5 problems, and only with 5 minutes remaining in the round. Congratulations to both on solving everything!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc1ewO42ui5ZQheKLn3FHAG0BthkYv-ItSy9v05HpRibbYVrMS7HfNBAPr4k2IdkFZych54LdSsGRCHxxq711gxS3sZTtW_nK9Ia5UCeHUvH4gJJBMH2Edfb82xGKtRt6QR21k9UfYmJ3lv_7xUORX1hTp7ewDy2-YBXiRlZVN6QtKpAzEpEm3QIST_M0/s4080/PXL_20241014_100517311.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc1ewO42ui5ZQheKLn3FHAG0BthkYv-ItSy9v05HpRibbYVrMS7HfNBAPr4k2IdkFZych54LdSsGRCHxxq711gxS3sZTtW_nK9Ia5UCeHUvH4gJJBMH2Edfb82xGKtRt6QR21k9UfYmJ3lv_7xUORX1hTp7ewDy2-YBXiRlZVN6QtKpAzEpEm3QIST_M0/w640-h482/PXL_20241014_100517311.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In &lt;a href=&quot;https://blog.mitrichev.ch/2025/11/a-treap-week.html&quot;&gt;my previous summary&lt;/a&gt;, I have mentioned my search for a nice and simple templated treap. I have decided to try building one myself, and you can see the result in action in &lt;a href=&quot;https://codeforces.com/contest/2164/submission/350784708&quot;&gt;this submission&lt;/a&gt;&amp;nbsp;to &lt;a href=&quot;https://codeforces.com/contest/2164/problem/F2&quot;&gt;problem F2&lt;/a&gt; from Global Round 30&amp;nbsp;(treap class itself at the top, its usage at the bottom).&lt;p&gt;&lt;/p&gt;&lt;p&gt;The API is modeled on &lt;a href=&quot;https://github.com/atcoder/ac-library/blob/master/document_en/lazysegtree.md&quot;&gt;lazysegtree&lt;/a&gt;, and it is parametrized with exactly the same types &lt;span style=&quot;font-family: courier;&quot;&gt;S&lt;/span&gt; and &lt;span style=&quot;font-family: courier;&quot;&gt;F&lt;/span&gt; and operations on them, with the same requirements on the composition of operations. A treap contains zero or more blocks, where each block represents an array of values of type &lt;span style=&quot;font-family: courier;&quot;&gt;S&lt;/span&gt;. We support the following operations:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;t.prod(block) -&amp;gt; S&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;:&amp;nbsp;&lt;/span&gt;computes op(...(op(op(e(), a), b), ...) if the given block has elements (a, b, ...). Runs in O(1).&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;t.apply(f, block)&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;: r&lt;/span&gt;eplaces each element x of the given block with f(x). Runs in O(1).&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;t.single(s) -&amp;gt; block&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;: c&lt;/span&gt;reates a new block with a single element with the given value. Runs in O(1).&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;t.destroy(block)&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;:&lt;/span&gt; destroys a block so that its memory can be reused. Runs in O(block_size).&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;t.concat(block1, block2) -&amp;gt; block&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;:&lt;/span&gt;&amp;nbsp;concatenates two blocks into one. The old blocks are consumed by this operation and are no longer valid after it. Runs in O(log(block_size)).&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;t.split_left(block, g) -&amp;gt; (block, block)&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;:&lt;/span&gt;&amp;nbsp;splits a block into a prefix and a suffix, given a predicate g. The split point is chosen in such a way that both of the following are true: either prefix is empty or g(prod(prefix)) is true; either suffix is empty or g(prod(concat(prefix, first_element(suffix)))) is false. If g is monotonic on prod(prefix), then this will find the point where it changes from true to false. Runs in O(log(block_size)).&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: courier;&quot;&gt;t.interleave_left(block1, block2, g) -&amp;gt; block&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;:&lt;/span&gt;&amp;nbsp;interleaves two blocks into one. The predicate g tells, given the products of a prefix of block1 and a prefix of block2, whether the last element of that prefix of block1 should come before the last element of that prefix of block2. Runs in O(smaller_block_size*log^2(block_size)) maybe?&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;This API tries to unify and generalize the two common cases of splitting by index and splitting by key. Splitting by index can be achieved by adding a 1 as one of the elements of struct &lt;i&gt;S&lt;/i&gt;, implementing &lt;i&gt;op&lt;/i&gt; as addition for that element, and using a predicate on that sum for splitting. Splitting by key can be achieved by storing the key as one of the elements of struct &lt;i&gt;S&lt;/i&gt;, and implementing &lt;i&gt;op&lt;/i&gt;(&lt;i&gt;k&lt;/i&gt;1, &lt;i&gt;k&lt;/i&gt;2)=&lt;i&gt;k&lt;/i&gt;2 (this is what the submission linked above does).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I&#39;ve also tried to make the API harder to misuse by making the block type moveable but non-copyable, so that the compiler helps make sure that we don&#39;t use a block after it has been consumed by an operation. This requires some &lt;span style=&quot;font-family: courier;&quot;&gt;std::move&lt;/span&gt;&#39;s in user code, but hopefully that is not too big of a burden.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We can also add more operations that can be expressed using the above ones, but allow a dedicated implementation with a better constant factor, such as insert (instead of single+interleave) or a product on a range (instead of two splits, product, then two concats back). However, I wanted to start with a small API to be able to iterate faster.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It is certainly not as powerful as a fully custom treap, but I think it can express most of the operations from &lt;a href=&quot;https://codeforces.com/blog/entry/136858&quot;&gt;BYOT&lt;/a&gt;, with the exception of range reverse and segment tree beats. And for me it is much more convenient to think in terms of concatenating and splitting arrays and applying associative operations on them, rather than directly in terms of treap implementation. What do you think, and do you have improvement suggestions?&lt;/div&gt;&lt;br /&gt;Thanks for reading, and check back soon for last week&#39;s summary!</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/4274146025016212539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/11/an-array-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/4274146025016212539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/4274146025016212539'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/11/an-array-week.html' title='An array week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEh0d30d9CisSw6QkvUQSCYMsFKAh_Lsn2Qnuu_6fJtA-l4j8XAqvW7T-zENr82ARvKJeeA3J3ylP-T9TR2Ky9OMV0uJuZixB1ZCaVOEz8KyDjJAK2JsNpo5bxBj8kbnDgYdUEfR65FLoSwg3V5rJHECI698PIfWNT-dsYyiKi4HG02vrMB1qVXVCnNH7Io=s72-w640-h128-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-6243577059607833213</id><published>2025-11-15T13:21:00.001+01:00</published><updated>2025-11-15T21:43:23.342+01:00</updated><title type='text'>A treap week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhW9kOtx5HIb7XeqpCavs9CjK_YdBkKksK5IWOoHcHBSZ_LZM8pluYTCeyDNM5d2ozTyT-V-iIjanPGTQ7crj1-ts_hfTgWoDzGvgF9ZQ_VUC56b459hAdJQxfmRWFqFYYrCGZJQSTMDw4T67f-GHxJAhOcnFkxfbJ6jjlGfQrnGr_ZYh0SER6ZJI15ZSo&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;274&quot; data-original-width=&quot;1138&quot; height=&quot;154&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhW9kOtx5HIb7XeqpCavs9CjK_YdBkKksK5IWOoHcHBSZ_LZM8pluYTCeyDNM5d2ozTyT-V-iIjanPGTQ7crj1-ts_hfTgWoDzGvgF9ZQ_VUC56b459hAdJQxfmRWFqFYYrCGZJQSTMDw4T67f-GHxJAhOcnFkxfbJ6jjlGfQrnGr_ZYh0SER6ZJI15ZSo=w640-h154&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Codeforces Global Round 30 was the main event of last week (&lt;a href=&quot;https://codeforces.com/contest/2164&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2164/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/148126&quot;&gt;analysis&lt;/a&gt;, &lt;a href=&quot;https://youtu.be/0VPcMQF6GJ8&quot;&gt;my screencast&lt;/a&gt;). I was doing quite well on the first six problems, but got bogged down with implementing treaps with some additional accounting for problem F2, spending more than an hour on that. Right after the contest ended, I had two thoughts:&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Wow, the people at the top of the scoreboard are so much better than me at implementation, how did they dig themselves out of this treap mess so fast?&lt;/li&gt;&lt;li&gt;I should implement some kind of templated treap and have it available for the next rounds. Currently I do not have a library of my own, and rely on the &lt;a href=&quot;https://github.com/atcoder/ac-library&quot;&gt;AtCoder library&lt;/a&gt; which has very nice templated segment trees and other algorithms, but not treaps.&lt;/li&gt;&lt;/ol&gt;Well, it turns out that the first thought was wrong. Out of the top 9 contestants (those that solved 8 problems), exactly the first three did not have treaps or splay trees in their solution for F2, but only segment trees plus standard STL data structures (while the next 6 had treaps or splay trees)! So these results clearly show that thinking some more to simplify the implementation beats just jumping into the first tedious simplementation approach one comes up with :) Well done to Otomachi_Una, Kevin114514 and dXqwq!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The second thought still stands though. However, it is not obvious to me what is the best templated abstraction for a treap. From the 9 contestants mentioned above, it seems that only hos.lyric has a &lt;a href=&quot;https://codeforces.com/contest/2164/submission/347746951&quot;&gt;templated splay tree&lt;/a&gt;, but even in her case the abstraction seems to leak the implementation details (push/pull), and the function splitAt might have been added specifically for this problem since it is not aligned with the rest of the abstraction, relying on the custom field &quot;size&quot; of the node that no other methods use. Compare this to AtCoder&#39;s &lt;a href=&quot;https://github.com/atcoder/ac-library/blob/master/document_en/lazysegtree.md&quot;&gt;lazysegtree&lt;/a&gt;, which is defined in abstract mathematical terms of applying two operations on ranges of data.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So, does somebody know a templated treap/splay tree abstraction that expresses the operations in abstract mathematical terms, and yet is as fast and powerful as tinkering with treap&#39;s implementation details?&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW_4fw9oI354RyKALRBdvxsib2C6CQag4UGjST36w1GFnExuv7crSar0cjD3pRzYldOOFDsWz0IqjckhlnwJp4VZ-79PTdzm5q1CfyMEmdVffIuiOAnQsBQkK9MBBiFLBCa_C8wEABr6ZGX4EOM-qtKYrQJ09dxv2r83Hbc_ICDlk12Od228-5NZYD1wU/s4080/PXL_20250219_100757730.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW_4fw9oI354RyKALRBdvxsib2C6CQag4UGjST36w1GFnExuv7crSar0cjD3pRzYldOOFDsWz0IqjckhlnwJp4VZ-79PTdzm5q1CfyMEmdVffIuiOAnQsBQkK9MBBiFLBCa_C8wEABr6ZGX4EOM-qtKYrQJ09dxv2r83Hbc_ICDlk12Od228-5NZYD1wU/w640-h482/PXL_20250219_100757730.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In &lt;a href=&quot;https://blog.mitrichev.ch/2025/11/a-qoj-week.html&quot;&gt;my previous summary&lt;/a&gt;, I have mentioned another&amp;nbsp;&lt;a href=&quot;https://codeforces.com/contest/2161/problem/F&quot;&gt;Codeforces problem&lt;/a&gt;: you are given a tree with &lt;i&gt;n&lt;/i&gt;&amp;lt;=5000 vertices. Consider the 2&lt;sup&gt;&lt;i&gt;n&lt;/i&gt;&lt;/sup&gt; ways to choose a subset &lt;i&gt;S&lt;/i&gt; of its vertices, and for each subset &lt;i&gt;S&lt;/i&gt; build a complete graph where &lt;i&gt;S&lt;/i&gt; is the vertex set, and every two vertices are connected by an edge with a weight equal to the length of the tree path connecting them. What is the sum of weights of minimum spanning trees of those 2&lt;sup&gt;&lt;i&gt;n&lt;/i&gt;&lt;/sup&gt;&amp;nbsp;graphs?&lt;p&gt;&lt;/p&gt;&lt;p&gt;A natural question to ask is: given a particular pair of vertices &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt;, in how many of the 2&lt;sup&gt;&lt;i&gt;n&lt;/i&gt;&lt;/sup&gt;&amp;nbsp;subsets will they be directly connected by an edge of the minimum spanning tree? If we can answer that question, then we can just add up those answers multiplied by the distance between &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt; to obtain the answer to the problem.&lt;/p&gt;&lt;p&gt;The first difficulty on that path is that &quot;the minimum spanning tree&quot; is not well defined, there might be multiple spanning trees of the same minimum weight. To deal with that, we can choose a particular minimum spanning tree, say, the one found by &lt;a href=&quot;https://en.wikipedia.org/wiki/Kruskal%27s_algorithm&quot;&gt;the Kruskal&#39;s algorithm&lt;/a&gt; that processes the edges in the order of weights, breaking ties in the lexicographical order of the edge ends.&lt;/p&gt;&lt;p&gt;In order for an edge between &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt; to be chosen by the algorithm, it is necessary and sufficient that there is no path connecting &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt; using the previous edges in the aforementioned order, namely using all edges of a smaller weight, and edges of the same weight that come before in the lexicographical order. Let us check how this path might go along the tree. Let us draw the tree in the following manner: the path from &lt;i&gt;a&lt;/i&gt; to &lt;i&gt;b&lt;/i&gt; is at the top, and a subtree grows from each of its vertices. We need to get from &lt;i&gt;a&lt;/i&gt; to &lt;i&gt;b&lt;/i&gt;, stopping only in vertices in the chosen subset &lt;i&gt;S&lt;/i&gt;, such that each jump satisfies the above criteria.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieyfTpY9hsuD2hxM6hDMipyHXq5P2ohZEn2aLqSm0MmRsARI6J3y2apwFroF8i2e0t7dfODe_gNxUyLObRO7MfD6a1dYvLjffkS9GB2NtC6m85Z-y5Q4NwCsAjjnXipxV2qLDCzL7593VLKO6umXDD0kkMJmGobw91KuXILXHePv-fGPbPeCLocn4XDdQ/s3981/PXL_20251115_102659429.MP~2.jpg&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1310&quot; data-original-width=&quot;3981&quot; height=&quot;210&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieyfTpY9hsuD2hxM6hDMipyHXq5P2ohZEn2aLqSm0MmRsARI6J3y2apwFroF8i2e0t7dfODe_gNxUyLObRO7MfD6a1dYvLjffkS9GB2NtC6m85Z-y5Q4NwCsAjjnXipxV2qLDCzL7593VLKO6umXDD0kkMJmGobw91KuXILXHePv-fGPbPeCLocn4XDdQ/w640-h210/PXL_20251115_102659429.MP~2.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Suppose there is a vertex &lt;i&gt;c&lt;/i&gt; in S, hanging somewhere from the middle of the path, such that d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)&amp;lt;d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;b&lt;/i&gt;) and d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)&amp;lt;d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;b&lt;/i&gt;), then we can just go from &lt;i&gt;a&lt;/i&gt; to &lt;i&gt;c&lt;/i&gt; to &lt;i&gt;b&lt;/i&gt;, so in those cases the edge between &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt; will not be chosen. Suppose &lt;i&gt;c&lt;/i&gt; hangs from the vertex &lt;i&gt;x&lt;/i&gt; on the path (&lt;i&gt;x&lt;/i&gt; might not be in &lt;i&gt;S&lt;/i&gt;, so we cannot stop there). Then d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)=d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)+d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;), d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;b&lt;/i&gt;)=d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)+d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;), d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)=d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)+d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;), so the above inequalities translate to d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)&amp;lt;d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;) and d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)&amp;lt;d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;), in other words d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)&amp;lt;min(d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;),d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)). So in order for the edge between &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt; to be chosen, we must have d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)&amp;gt;=min(d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;),d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)) for all &lt;i&gt;c&lt;/i&gt; in &lt;i&gt;S&lt;/i&gt;.&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, suppose that inequality is strict: d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)&amp;gt;min(d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;),d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)). Then it&#39;s not hard to see that instead of going to/from &lt;i&gt;c&lt;/i&gt; when passing through &lt;i&gt;x&lt;/i&gt;, we can go directly to/from &lt;i&gt;a&lt;/i&gt; or &lt;i&gt;b&lt;/i&gt;, therefore such vertices are not useful to construct the path we are looking for. So the existence or nonexistence of the path depends only on the vertices &lt;i&gt;c&lt;/i&gt; with d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)&amp;lt;=min(d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;),d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)). Since we already know that the path will exist when there is &lt;i&gt;c&lt;/i&gt; such that d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)&amp;lt;min(d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;),d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)), the only interesting remaining case is where there is one or more vertices&amp;nbsp;&lt;i&gt;c&lt;/i&gt; such that d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)=min(d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;),d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)).&lt;/p&gt;&lt;p&gt;The distances between such vertices can be equal to d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;b&lt;/i&gt;), so this is where the lexicographical ordering of the edges comes into play. It is possible to carefully consider it and solve the problem, but we can also make another small observation instead: vertices&amp;nbsp;&lt;i&gt;c&lt;/i&gt;&amp;nbsp;such that d(&lt;i&gt;x&lt;/i&gt;,&lt;i&gt;c&lt;/i&gt;)=min(d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;),d(&lt;i&gt;b&lt;/i&gt;,&lt;i&gt;x&lt;/i&gt;)) are exactly those vertices that are at the distance of d(&lt;i&gt;a&lt;/i&gt;,&lt;i&gt;b&lt;/i&gt;)/2 from point &lt;i&gt;z&lt;/i&gt;&amp;nbsp;that is the middle of the path between &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt; (note that &lt;i&gt;z&lt;/i&gt; is either a vertex or a midpoint of an edge)!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjK_FBX5p7aDcpzsRabAgPWxnkipWyK7TJLP5OpXKVNGgwOvem12sq48DezVS8b8SuF3vSo7hJRsfZKyVh6qEnk7kE3bC5uFuTLPvmgYvYVEvfvYtNs5VUKPFx9ePwzFELnRtZZuFZfSBgkSy1JKPXDnQV1xhyjveEheDeFRLUhyphenhyphenG55XqSjtJ-06uhpTmE/s2996/PXL_20251115_120805382~2.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;2014&quot; data-original-width=&quot;2996&quot; height=&quot;430&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjK_FBX5p7aDcpzsRabAgPWxnkipWyK7TJLP5OpXKVNGgwOvem12sq48DezVS8b8SuF3vSo7hJRsfZKyVh6qEnk7kE3bC5uFuTLPvmgYvYVEvfvYtNs5VUKPFx9ePwzFELnRtZZuFZfSBgkSy1JKPXDnQV1xhyjveEheDeFRLUhyphenhyphenG55XqSjtJ-06uhpTmE/w640-h430/PXL_20251115_120805382~2.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;This raises a natural question: what if, instead of focusing on the edge between &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt;, we focus on all edges of the spanning tree with the given middle point &lt;i&gt;z&lt;/i&gt;? If &lt;i&gt;d&lt;/i&gt; is the smallest distance between &lt;i&gt;z&lt;/i&gt; and a vertex in &lt;i&gt;S&lt;/i&gt;, then from the above argument we can see that only edges of length 2&lt;i&gt;d&lt;/i&gt; can exist in the spanning tree. If we root the original tree at &lt;i&gt;z&lt;/i&gt;, and count the number &lt;i&gt;m&lt;/i&gt; of subtrees of the root that contain a vertex at depth &lt;i&gt;d&lt;/i&gt;&amp;nbsp;(none of them will have a vertex at depth less than &lt;i&gt;d&lt;/i&gt; by the definition of &lt;i&gt;d&lt;/i&gt;), then it&#39;s not hard to observe that we will have exactly &lt;i&gt;m&lt;/i&gt;-1 edges with length 2&lt;i&gt;d&lt;/i&gt; and middle point &lt;i&gt;z&lt;/i&gt; in the spanning tree. Note that in case &lt;i&gt;z&lt;/i&gt; is a midpoint of an edge, then &lt;i&gt;m&lt;/i&gt;&amp;lt;=2.&lt;p&gt;&lt;/p&gt;&lt;p&gt;So we just need to count for each subtree how many ways are there to choose &lt;i&gt;S&lt;/i&gt; in this subtree such that the smallest depth is &lt;i&gt;d&lt;/i&gt;, and then we can combine those values to obtain the answer using the above observation, and then sum up those answers over all choices of &lt;i&gt;z&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;It was not strictly necessary to go through the Kruskal&#39;s algorithm and the lexicographical order part. Instead, we can immediately start with the &quot;consider all edges of the spanning tree with the given middle point &lt;i&gt;z&lt;/i&gt;&quot; argument, and the solution will be short and beautiful. However, I also wanted to demonstrate how one can arrive at this idea analytically.&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back next week!&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/6243577059607833213/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/11/a-treap-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/6243577059607833213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/6243577059607833213'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/11/a-treap-week.html' title='A treap week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhW9kOtx5HIb7XeqpCavs9CjK_YdBkKksK5IWOoHcHBSZ_LZM8pluYTCeyDNM5d2ozTyT-V-iIjanPGTQ7crj1-ts_hfTgWoDzGvgF9ZQ_VUC56b459hAdJQxfmRWFqFYYrCGZJQSTMDw4T67f-GHxJAhOcnFkxfbJ6jjlGfQrnGr_ZYh0SER6ZJI15ZSo=s72-w640-h154-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-3852362980945272449</id><published>2025-11-05T21:44:00.003+01:00</published><updated>2025-11-05T21:44:41.590+01:00</updated><title type='text'>A QOJ week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEidVSohHPZTyqI2ulpJFxXjyPB9Yy1T7yECFwlN3FK14NkWE3zwt1_EY9wxxHV1IWzxMTiDUYZhItX2hmcAOpOL65tWch3LGviaP-Ezykp7PPKZVZwi-FaRn17nlugwEFslKe7Edh4Ikl3jy52zOrNzUevevDtH9hLG1uilhDoTPHbODCjF2Y3X_IHnoTI&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;278&quot; data-original-width=&quot;1106&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEidVSohHPZTyqI2ulpJFxXjyPB9Yy1T7yECFwlN3FK14NkWE3zwt1_EY9wxxHV1IWzxMTiDUYZhItX2hmcAOpOL65tWch3LGviaP-Ezykp7PPKZVZwi-FaRn17nlugwEFslKe7Edh4Ikl3jy52zOrNzUevevDtH9hLG1uilhDoTPHbODCjF2Y3X_IHnoTI=w640-h160&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Pinely Round 5 started the competitive part of the last week on Thursday (&lt;a href=&quot;https://codeforces.com/contest/2161&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2161/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/147941&quot;&gt;analysis&lt;/a&gt;). This was my first individual appearance in a screenshot on this blog since &lt;a href=&quot;https://blog.mitrichev.ch/2024/04/a-jiangly-week.html&quot;&gt;April 2024&lt;/a&gt;, so I think it went pretty well :) I was figuring out the solutions pretty quickly, and did not get stuck in implementation like I often do. However, it was not nearly good enough for the first place, since tourist was both the fastest, and with zero incorrect attempts. Congratulations on the convincing win!&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://codeforces.com/contest/2161/problem/F&quot;&gt;Problem F&lt;/a&gt; gave me a nice warm feeling when I figured out the solution, so maybe it will be enjoyable for you as well: you are given a tree with &lt;i&gt;n&lt;/i&gt;&amp;lt;=5000 vertices. Consider the 2&lt;sup&gt;&lt;i&gt;n&lt;/i&gt;&lt;/sup&gt; ways to choose a subset &lt;i&gt;S&lt;/i&gt; of its vertices, and for each subset &lt;i&gt;S&lt;/i&gt; build a complete graph where &lt;i&gt;S&lt;/i&gt; is the vertex set, and every two vertices are connected by an edge with a weight equal to the length of the tree path connecting them. What is the sum of weights of minimum spanning trees of those 2&lt;sup&gt;&lt;i&gt;n&lt;/i&gt;&lt;/sup&gt;&amp;nbsp;graphs?&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhQi683-Jg0GGRoErBfSSzT3ekPkkhK3hLbIb2rxYixrM2aFVVo3ZfJ30bvRq_SRuQNeg63WKjvD4ytoHNqjreC84lXS_K3i3JnBAE07csAdArLUzr1TNwNhI5_liP6_AlqHXXIqLXitZjjKw3AAZCRkCB1w3Px2sLgIc17hn4HC57m_S5_MAliek5o-BA&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;239&quot; data-original-width=&quot;1104&quot; height=&quot;138&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhQi683-Jg0GGRoErBfSSzT3ekPkkhK3hLbIb2rxYixrM2aFVVo3ZfJ30bvRq_SRuQNeg63WKjvD4ytoHNqjreC84lXS_K3i3JnBAE07csAdArLUzr1TNwNhI5_liP6_AlqHXXIqLXitZjjKw3AAZCRkCB1w3Px2sLgIc17hn4HC57m_S5_MAliek5o-BA=w640-h138&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The 4th Universal Cup Stage 4: Chengdu took place on Saturday, as usual (&lt;a href=&quot;https://contest.ucup.ac/contest/2567&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2567&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://assets.ucup.ac/tutorials/tutorials-4-04-zh.pdf&quot;&gt;analysis in Chinese&lt;/a&gt;). Team USA1 won the third stage out of four this year, defying the parity rule. The second place went to a team that is not in &lt;a href=&quot;https://ucup.ac/rating/&quot;&gt;the season rating&lt;/a&gt;, so I assume this was a team that was participating in the original onsite contest that this stage was a mirror of. Congratulations to both teams on solving all problems!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEj6M867shNkHhycszN88HaJAGU8q9kPUIaDD1nIK38uwYYLfaWFpkiw77YUAuqPt9COTVzS8Xr7B0rhHqSKf69VpDnrajSWog9wiNHucBR8vpPkirOHam9mDOITARcMBymLtl8s4vsUP8UvTnpEaXcJAtlgYhKPi_6oD3Htn-_CR-lBxjeH6vHuelFVsd8&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;381&quot; data-original-width=&quot;1439&quot; height=&quot;170&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEj6M867shNkHhycszN88HaJAGU8q9kPUIaDD1nIK38uwYYLfaWFpkiw77YUAuqPt9COTVzS8Xr7B0rhHqSKf69VpDnrajSWog9wiNHucBR8vpPkirOHam9mDOITARcMBymLtl8s4vsUP8UvTnpEaXcJAtlgYhKPi_6oD3Htn-_CR-lBxjeH6vHuelFVsd8=w640-h170&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Yandex Cup 2025 Qualification Round&amp;nbsp; wrapped up the week on Sunday (&lt;a href=&quot;https://contest.yandex.com/contest/84268/standings/&quot;&gt;results&lt;/a&gt;, top 5 on the left). A few people were in contention on the easier problems, but starting from problem J ecnerwala was significantly faster than the competition, so it is not a surprise that only he was able to solve everything this time. Well done!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;After the &lt;a href=&quot;https://qoj.ac/blog/qingyu/blog/1339&quot;&gt;3rd Universal Cup Semifinals&lt;/a&gt;, this was the second big contest that &lt;a href=&quot;https://codeforces.com/blog/entry/146866&quot;&gt;required proctoring&lt;/a&gt; for those who &lt;a href=&quot;https://codeforces.com/blog/entry/146866?#comment-1322892&quot;&gt;want to qualify&lt;/a&gt; to the onsite round, and it was certainly not the last one to do so.&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSBu8YA_7Mfi3Vh8Kj4G5eeEGNJnt-CpCwNxebHJWo6bUVP7c3mgKtp8fKjqPKWaz9JlqKfmjm8HzBrT5WV4emIA7zUSSfAdY_jX4PWJpilgAvPT2J1mEeyZ4JlhV9dmBIkq-aD5s4FZZhz6zJ-7yV1nMQcAmvvPp-UFBfSdoDUwvn0WfW1xt2BEwb_ME/s4080/PXL_20251101_131735862.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSBu8YA_7Mfi3Vh8Kj4G5eeEGNJnt-CpCwNxebHJWo6bUVP7c3mgKtp8fKjqPKWaz9JlqKfmjm8HzBrT5WV4emIA7zUSSfAdY_jX4PWJpilgAvPT2J1mEeyZ4JlhV9dmBIkq-aD5s4FZZhz6zJ-7yV1nMQcAmvvPp-UFBfSdoDUwvn0WfW1xt2BEwb_ME/w640-h482/PXL_20251101_131735862.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In &lt;a href=&quot;https://blog.mitrichev.ch/2025/10/a-moonlit-week.html&quot;&gt;my previous summary&lt;/a&gt;, I have mentioned &lt;a href=&quot;https://atcoder.jp/contests/agc074/tasks/agc074_c&quot;&gt;an AtCoder problem&lt;/a&gt;: you are given a single integer &lt;i&gt;n&lt;/i&gt;&amp;lt;=2&lt;sup&gt;10&lt;/sup&gt;, and you need to produce a sequence &lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; of &lt;i&gt;n&lt;/i&gt; integers such that 0&amp;lt;=&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;2&lt;sup&gt;30&lt;/sup&gt;, such that for every value of &lt;i&gt;k&lt;/i&gt; between 1 and &lt;i&gt;n&lt;/i&gt; there exists a number &lt;i&gt;a&lt;/i&gt; such that the longest strictly increasing subsequence of the sequence&amp;nbsp;&lt;i&gt;q&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;amp;&lt;i&gt;a&lt;/i&gt; has length &lt;i&gt;k&lt;/i&gt;. Here &amp;amp; denotes bitwise and, in other words we consider a certain subset of bits of&amp;nbsp;&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;, the same subset for all &lt;i&gt;i&lt;/i&gt;.&lt;p&gt;&lt;/p&gt;&lt;p&gt;Many, if not most, constructive problems that have a single integer &lt;i&gt;n&lt;/i&gt; in the input are solved by figuring out a way to produce solutions for 2&lt;i&gt;n&lt;/i&gt; and 2&lt;i&gt;n&lt;/i&gt;+1 from a solution for &lt;i&gt;n&lt;/i&gt;, and this problem was also one of those. The constraints strongly hinted that we need to learn to double &lt;i&gt;n&lt;/i&gt; using at most 3 additional bits.&lt;/p&gt;&lt;p&gt;Suppose we have a sequence&amp;nbsp;&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;that solves the problem for some &lt;i&gt;n&lt;/i&gt;. There are actually two ways to easily double the LIS length: we can either add a new bit at the end, replacing each number&amp;nbsp;&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;with two consecutive numbers 2&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;and 2&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;+1, or add a new bit in the beginning, appending a second copy of the sequence sequence&amp;nbsp;&lt;i&gt;p&lt;sub&gt;i&amp;nbsp;&lt;/sub&gt;&lt;/i&gt;to itself, but with all numbers increased by the same value 2&lt;sup&gt;&lt;i&gt;t&lt;/i&gt;&lt;/sup&gt;&amp;nbsp;chosen in such a way that all&amp;nbsp;&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;2&lt;sup&gt;&lt;i&gt;t&lt;/i&gt;&lt;/sup&gt;. In both cases we set the corresponding bit of &lt;i&gt;a&lt;/i&gt; to 1. This way by adding just one more bit we are now able to get all even LIS lengths from 2 to 2&lt;i&gt;n&lt;/i&gt;. But what to do about the odd lengths?&lt;/p&gt;&lt;p&gt;Let us use one more bit, and append a number 2&lt;sup&gt;&lt;i&gt;r&amp;nbsp;&lt;/i&gt;&lt;/sup&gt;that is bigger than all existing numbers to the end of the (doubled) sequence. Now if we use the same &lt;i&gt;a&lt;/i&gt; as before, the LIS length will still be 2&lt;i&gt;k&lt;/i&gt;&amp;nbsp;since the new number becomes 0 if the &lt;i&gt;r&lt;/i&gt;-th bit of &lt;i&gt;a&lt;/i&gt; is not set. However, if we set the &lt;i&gt;r&lt;/i&gt;-th bit of a to 1, then the LIS length will be 2&lt;i&gt;k&lt;/i&gt;+1, since the new big number can be appended to any increasing sequence. This means that we now have a sequence of length 2&lt;i&gt;n&lt;/i&gt;+1 for which we can get any LIS length between 2 and 2&lt;i&gt;n&lt;/i&gt;+1. The only missing length is 1, but that is also easy to achieve: just set &lt;i&gt;a&lt;/i&gt;=0.&lt;/p&gt;&lt;p&gt;So we can go from &lt;i&gt;n&lt;/i&gt; to 2&lt;i&gt;n&lt;/i&gt;+1 using 2 additional bits. What about going from &lt;i&gt;n&lt;/i&gt; to 2&lt;i&gt;n&lt;/i&gt;? Well, actually we can use the &quot;append a big power of two&quot; trick once again, and go from &lt;i&gt;n&lt;/i&gt; to 2&lt;i&gt;n&lt;/i&gt;+2 using 3 additional bits. Being able to go from &lt;i&gt;n&lt;/i&gt; to 2&lt;i&gt;n&lt;/i&gt;+1 and 2&lt;i&gt;n&lt;/i&gt;+2 means that we can get any number if we also have solutions for the base cases &lt;i&gt;n&lt;/i&gt;=1 and &lt;i&gt;n&lt;/i&gt;=2.&lt;/p&gt;&lt;p&gt;As is often the case with AtCoder problems, after seeing the solution one cannot fathom struggling for several hours to come up with it, it looks so straightforward :)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEEQz2IZ0FKCc3RYHRu7_ejRKA-L51nJwfSeVYJ1TwffXB3uOV6bRlMnBs_SVYTtCrfkeWaGa1arjFGgF1l9AHpra1D31rJ1h0OUBwVLt81srT0W1s-TquATTlJ-ZrIK00BTYiicCh3fO_QOS6LcsCb1UYqx0-WWMrduN2loB2MLQ4ZmgU_69xthbCOg4/s4080/PXL_20250427_090425581-EDIT.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;2421&quot; data-original-width=&quot;4080&quot; height=&quot;380&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEEQz2IZ0FKCc3RYHRu7_ejRKA-L51nJwfSeVYJ1TwffXB3uOV6bRlMnBs_SVYTtCrfkeWaGa1arjFGgF1l9AHpra1D31rJ1h0OUBwVLt81srT0W1s-TquATTlJ-ZrIK00BTYiicCh3fO_QOS6LcsCb1UYqx0-WWMrduN2loB2MLQ4ZmgU_69xthbCOg4/w640-h380/PXL_20250427_090425581-EDIT.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;I was discussing an &lt;a href=&quot;https://blog.mitrichev.ch/2016/04/a-doubles-week.html&quot;&gt;old Open Cup gem&lt;/a&gt; with my friends recently, motivated by a lecture on binary search for beginner Swiss high school students. I was almost certain there is no way to upsolve that problem now. However, it turns out that this problem (and probably many other old Open Cup contests?) are &lt;a href=&quot;https://qoj.ac/contest/2528/problem/14119&quot;&gt;now available for upsolving on QOJ.ac&lt;/a&gt;, the same website that hosts Universal Cup. Huge thanks to the admins of QOJ for preserving the old contests!&lt;p&gt;&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back next week!&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/3852362980945272449/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/11/a-qoj-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/3852362980945272449'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/3852362980945272449'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/11/a-qoj-week.html' title='A QOJ week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEidVSohHPZTyqI2ulpJFxXjyPB9Yy1T7yECFwlN3FK14NkWE3zwt1_EY9wxxHV1IWzxMTiDUYZhItX2hmcAOpOL65tWch3LGviaP-Ezykp7PPKZVZwi-FaRn17nlugwEFslKe7Edh4Ikl3jy52zOrNzUevevDtH9hLG1uilhDoTPHbODCjF2Y3X_IHnoTI=s72-w640-h160-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-778220328787860973</id><published>2025-10-26T18:28:00.002+01:00</published><updated>2025-10-26T20:54:48.910+01:00</updated><title type='text'>A moonlit week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEj-2QySRcz4SDvIgAuGwNsCAmuXr57v2e3WDPrvs3JUUc9M-OGooSYEqEb_tt1HUfXhxb6q2o7gcrlK1SWftuanR0fW06dVKKWBk-_EAbx3dYKnM6O78o7rhbzaGk1FSynBe3SDxvcByEFQ6iCTXR7CGNm4_umXZ4-LU2zoKvZQ7OwK18dk8HxfdatR5Wk&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;232&quot; data-original-width=&quot;970&quot; height=&quot;154&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEj-2QySRcz4SDvIgAuGwNsCAmuXr57v2e3WDPrvs3JUUc9M-OGooSYEqEb_tt1HUfXhxb6q2o7gcrlK1SWftuanR0fW06dVKKWBk-_EAbx3dYKnM6O78o7rhbzaGk1FSynBe3SDxvcByEFQ6iCTXR7CGNm4_umXZ4-LU2zoKvZQ7OwK18dk8HxfdatR5Wk=w640-h154&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The Universal Cup Stage 3: Polar was the first event of this week (&lt;a href=&quot;https://contest.ucup.ac/contest/2559&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2559&quot;&gt;results&lt;/a&gt;, top 5 on the left, still not updated &lt;a href=&quot;https://ucup.ac/rating/&quot;&gt;cup standings&lt;/a&gt;). In all three stages of this season the first two places went to the same two teams, and in odd-numbered rounds team USA1 comes out on top, if only by less than one wrong submission this time. Congratulations to both season leaders!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg4kET5DUOS2cT-iyBqjABdYI3_O_DOHgKr6At33YziuB7e6k0KUqmVdQqTCGihhlo5bVapBS49ITc9ebbszlKFgOkkA1tbqh0ToLbIuPtWTF_efZBGuqR5D7Ywft7jv7HQG-yGnB5x4eB_MkjQHWmMRMvJi09yCPg4B_KSuFdupVO-cXh2GFJHa8bc1Ec&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;335&quot; data-original-width=&quot;829&quot; height=&quot;258&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg4kET5DUOS2cT-iyBqjABdYI3_O_DOHgKr6At33YziuB7e6k0KUqmVdQqTCGihhlo5bVapBS49ITc9ebbszlKFgOkkA1tbqh0ToLbIuPtWTF_efZBGuqR5D7Ywft7jv7HQG-yGnB5x4eB_MkjQHWmMRMvJi09yCPg4B_KSuFdupVO-cXh2GFJHa8bc1Ec=w640-h258&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;AtCoder Grand Contest 074 wrapped up the week just a few hours ago (&lt;a href=&quot;https://atcoder.jp/contests/agc074/tasks&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://atcoder.jp/contests/agc074/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://atcoder.jp/contests/agc074/editorial&quot;&gt;analysis&lt;/a&gt;, &lt;a href=&quot;https://clist.by/standings/atcoder-race-ranking-2025-algorithm-57173720/&quot;&gt;race standings&lt;/a&gt;). Just one minute before the end of the round it seemed like Nachia executed a perfect strategy, solving C and B first, then deciding to go for D instead of A since it was clear at that point that A+B+C would not be enough to win the round, and getting D with 15 minutes remaining to go on top with a unique set of problems solved.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;However, ksun48 made not one but two submissions on C during the last minute, one of which turned out to be correct. How does one submit, find and fix a bug, and submit again, all within the last minute of the round? Well done, Kevin!&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I have spent most of the round on the same problem C. It was clear from the constraints that one should dig in the direction of going from ~&lt;i&gt;n&lt;/i&gt; to ~2&lt;i&gt;n&lt;/i&gt;&amp;nbsp;using 3 additional bits, and in the end this is exactly how my solution works, but somehow this digging took me more than 2 hours, mostly on paper.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I think it took me so long since I have made a reduction that made the solution more difficult, and did not consider rolling it back (instead, I have persevered and solved the more difficult reduced problem): I was looking for a way to configure the 3 additional bits in such a way that we can go from a LIS of length&amp;nbsp;&lt;i&gt;k&lt;/i&gt;&amp;nbsp;for &lt;i&gt;n&lt;/i&gt;/2&amp;nbsp;either to lengths &lt;i&gt;k&lt;/i&gt;, 2&lt;i&gt;k&lt;/i&gt; and 2&lt;i&gt;k&lt;/i&gt;+1 or to lengths&amp;nbsp;&lt;i&gt;k&lt;/i&gt;, 2&lt;i&gt;k+1&lt;/i&gt;&amp;nbsp;and 2&lt;i&gt;k&lt;/i&gt;+2, depending on the parity of &lt;i&gt;n&lt;/i&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The reason I wanted three options instead of the usual two was that the 2&lt;i&gt;k&lt;/i&gt;+&lt;i&gt;x&lt;/i&gt; options would not cover small values of LIS, so I thought it would make sense to make sure we also can keep &lt;i&gt;k&lt;/i&gt; unchanged; however, on further thought after the round it became clear that the small values not covered are only 1 and possibly 2; and it is always very easy to obtain a LIS of 1 by just making everything equal, and also not hard to obtain a LIS of 2 by making almost everything equal.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Despite a few spoilers above, I hope you can still enjoy solving &lt;a href=&quot;https://atcoder.jp/contests/agc074/tasks/agc074_c&quot;&gt;that problem&lt;/a&gt; if you have not already: you are given a single integer &lt;i&gt;n&lt;/i&gt;&amp;lt;=2&lt;sup&gt;10&lt;/sup&gt;, and you need to produce a sequence &lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; of &lt;i&gt;n&lt;/i&gt; integers such that 0&amp;lt;=&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;2&lt;sup&gt;30&lt;/sup&gt;, such that for every value of &lt;i&gt;k&lt;/i&gt; between 1 and &lt;i&gt;n&lt;/i&gt; there exists a number &lt;i&gt;a&lt;/i&gt; such that the longest strictly increasing subsequence of the sequence&amp;nbsp;&lt;i&gt;q&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;amp;&lt;i&gt;a&lt;/i&gt; has length &lt;i&gt;k&lt;/i&gt;. Here &amp;amp; denotes bitwise and, in other words we consider a certain subset of bits of&amp;nbsp;&lt;i&gt;p&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;, the same subset for all &lt;i&gt;i&lt;/i&gt;.&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgDYP-1OjPdZ4ObUYXWzExfwg5VKRSb3oyeooQuvqUDakoQuUR4KaNFQqHJMlTN8NAk9o5ScLZd4ABYWVIljkYuBE2CpEgFyXWbMCPPZmNQ1v8tTOc4RRnzlCDUwc-MdU5vZhyphenhyphenRx4q4vFIPH0UssXVwJ2hElSxyjgdpAptd2vMRCUBmS0c4lh7OmQ5wx8/s3811/PXL_20250809_204433155-EDIT.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1976&quot; data-original-width=&quot;3811&quot; height=&quot;332&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgDYP-1OjPdZ4ObUYXWzExfwg5VKRSb3oyeooQuvqUDakoQuUR4KaNFQqHJMlTN8NAk9o5ScLZd4ABYWVIljkYuBE2CpEgFyXWbMCPPZmNQ1v8tTOc4RRnzlCDUwc-MdU5vZhyphenhyphenRx4q4vFIPH0UssXVwJ2hElSxyjgdpAptd2vMRCUBmS0c4lh7OmQ5wx8/w640-h332/PXL_20250809_204433155-EDIT.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In &lt;a href=&quot;https://blog.mitrichev.ch/2025/10/a-major-week.html&quot;&gt;my previous summary&lt;/a&gt;, I have mentioned &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-1/problems/D&quot;&gt;a Hacker Cup problem&lt;/a&gt;: you are given a string of 0s and 1s of length &amp;lt;=600000. Two players are playing a game, making moves in turns. On each move of the first player, they erase any prefix of the string that ends with a 0. On each move of the second player, they erase any suffix of the string that starts with a 1. The player who cannot make a move loses. Who will win if both play optimally?&lt;p&gt;&lt;/p&gt;&lt;p&gt;First of all, the first player always takes a 0, and the second player always takes a 1. Naively, one might think that we should just count if there are more 0s or 1s in the string. However, it is very easy to come up with a counter-example: string 110 has more 1s than 0s, but the first player still wins because they can erase it in one go. The 1s in the beginning of the string don&#39;t really matter, as long as there is at least one 0.&lt;/p&gt;&lt;p&gt;However, since having more 0s still seems useful for the first player, a somewhat natural idea is to check: what if the first player tries to make a move that maximizes the balance of the remaining string — the difference between the number of 0s and 1s? Here a counterexample is also not that hard: from the string 0100 we can go to two different strings 100 and 0 with the maximum balance of 1, however if we go to 100 then the second player can take the remaining string and win, while if we go to 0, the second player loses.&lt;/p&gt;&lt;p&gt;Guided by this counterexample, what if we always break ties by choosing the shortest possible string with the maximum balance? After spending some time finding yet another counterexample to this approach and failing, I&#39;ve decided to look for a proof that it works instead.&lt;/p&gt;&lt;p&gt;Suppose we have used that strategy for the first move, and the remaining string has some non-negative balance (it feels intuitive that the balance has to be non-negative for us to win). What happens to the balance after the move of the second player? After some experimentation, we can notice that it always becomes strictly positive. And indeed, it is not hard to prove by contradiction: suppose it is non-positive after the move of the second player. Suppose the string remaining after the move of the first player is &lt;i&gt;s&lt;/i&gt;, and the second player has removed then removed the suffix &lt;i&gt;u&lt;/i&gt;, and what remained is &lt;i&gt;t&lt;/i&gt;, so&amp;nbsp;&lt;i&gt;s&lt;/i&gt;=&lt;i&gt;tu&lt;/i&gt;.&amp;nbsp;&lt;/p&gt;&lt;p&gt;The balance of &lt;i&gt;s&lt;/i&gt; is non-negative, the balance of &lt;i&gt;t&lt;/i&gt; is non-positive, and &lt;i&gt;u&lt;/i&gt; starts with a 1. Since the balance of &lt;i&gt;u&lt;/i&gt; is the balance of &lt;i&gt;s&lt;/i&gt; minus the balance of &lt;i&gt;t&lt;/i&gt;, is is also non-negative, so it must have a 0. Consider its first 0, which splits the string &lt;i&gt;u&lt;/i&gt; as &lt;i&gt;u&lt;/i&gt;=&lt;i&gt;v&lt;/i&gt;0&lt;i&gt;w&lt;/i&gt;, where &lt;i&gt;v&lt;/i&gt; consists only of 1s. But then the first player could have additionally erased the string &lt;i&gt;tv&lt;/i&gt;0 in their first move. Since the balance of &lt;i&gt;t&lt;/i&gt; is non-positive, and the balance of &lt;i&gt;v&lt;/i&gt;0 is non-positive, the balance of &lt;i&gt;tv&lt;/i&gt;0 is non-positive, which means that the balance of &lt;i&gt;w&lt;/i&gt; is the same or higher than the balance of &lt;i&gt;s=&lt;/i&gt;&lt;i&gt;tv&lt;/i&gt;0&lt;i&gt;w&lt;/i&gt;. But this contradicts the choice of &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;So, after the move of the second player the balance will become strictly positive. But then we can apply the same approach (make the move that maximizes the balance of the remaining string, breaking ties to shorter remaining strings), and the balance of the remaining string will be non-negative (since at least if we take the first 0 it is non-negative, and we maximize it), so we can repeat this until we win.&lt;/p&gt;&lt;p&gt;We can already submit our solution at this point, but formally speaking we also need to prove that if the first player cannot make a move that leaves a string with a non-negative balance, then the second player wins. And indeed, we can apply the same argument as above: if we have left a string with a strictly negative balance, then from the point of view of the second player it has a strictly positive balance, and they can apply exactly the same strategy as above to win.&lt;/p&gt;&lt;p&gt;This solution is longer than the one in &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-1/solutions&quot;&gt;the editorial&lt;/a&gt;, but it is how I solved the problem during the round, and I hope it shows how to arrive at a solution without having to pull an idea out of thin air, for example an idea to consider balanced parentheses sequences as the editorial does.&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back next week!&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/778220328787860973/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/10/a-moonlit-week.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/778220328787860973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/778220328787860973'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/10/a-moonlit-week.html' title='A moonlit week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEj-2QySRcz4SDvIgAuGwNsCAmuXr57v2e3WDPrvs3JUUc9M-OGooSYEqEb_tt1HUfXhxb6q2o7gcrlK1SWftuanR0fW06dVKKWBk-_EAbx3dYKnM6O78o7rhbzaGk1FSynBe3SDxvcByEFQ6iCTXR7CGNm4_umXZ4-LU2zoKvZQ7OwK18dk8HxfdatR5Wk=s72-w640-h154-c" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-2261454959923411613</id><published>2025-10-24T21:54:00.002+02:00</published><updated>2025-10-24T23:02:59.767+02:00</updated><title type='text'>A major week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgUN-90bQ6qHSZlBDUqS0N3ufS1auAGE-zSGq5OgNQA6KL9hTp_AoH2T-Tf0GAUemTbyL7mRTSwV-RdkGikhtBCELC8Nb8OcAQoMBoCB5N15bA8sFotGjGtjTe2ka2eswdyYt2mPNlHn3a17-U9Cxlq5GqhweQG9WNyqZm24gSPb4DwWlGXEbsO5gviO50&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;236&quot; data-original-width=&quot;1217&quot; height=&quot;124&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgUN-90bQ6qHSZlBDUqS0N3ufS1auAGE-zSGq5OgNQA6KL9hTp_AoH2T-Tf0GAUemTbyL7mRTSwV-RdkGikhtBCELC8Nb8OcAQoMBoCB5N15bA8sFotGjGtjTe2ka2eswdyYt2mPNlHn3a17-U9Cxlq5GqhweQG9WNyqZm24gSPb4DwWlGXEbsO5gviO50=w640-h124&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Meta Hacker Cup 2025 Round 1 was the main event of last week (&lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-1/problems/D&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-1/scoreboard&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-1/solutions&quot;&gt;analysis&lt;/a&gt;). As usual in the early Hacker Cup rounds, one has to balance the speed against the amount of effort you spend to test your own solutions before attempting to submit them. There is just one attempt per problem, and the submission result is only revealed after the round ends (a pretty unique setup for today&#39;s contests, but one that I think makes the competition more exciting and emphasizes the useful testing skills!), and at the same time you only need to be in top &lt;i&gt;n&lt;/i&gt; to advance, your score does not matter for the future rounds. It does matter for the bragging rights though, so well done to Geothermal on being much faster than everybody else!&lt;p&gt;&lt;/p&gt;&lt;p&gt;The Hacker Cup is now the &quot;Major Individual Competition&quot; (according to &lt;a href=&quot;https://cphof.org/about&quot;&gt;cphof&lt;/a&gt;) that was held the most years among those still happening, this one is the 15th edition! TopCoder Open/Invitational is still in the overall lead with 22 editions, but that number is not going to increase further. Huge thanks to the organizers for putting it together year after year, and I&#39;m looking forward to participating in the next 15, and of course to you bringing back the onsite finals :)&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.facebook.com/codingcompetitions/hacker-cup/2025/round-1/problems/D&quot;&gt;Problem D&lt;/a&gt; was quite nice, and you can also solve it as a math problem without any computer help. You are given a string of 0s and 1s (check out the original problem statement for the more colorful story!) of length &amp;lt;=600000. Two players are playing a game, making moves in turns. On each move of the first player, they erase any prefix of the string that ends with a 0. On each move of the second player, they erase any suffix of the string that starts with a 1. The player who cannot make a move loses. Who will win if both play optimally?&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back next week!&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/2261454959923411613/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/10/a-major-week.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/2261454959923411613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/2261454959923411613'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/10/a-major-week.html' title='A major week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgUN-90bQ6qHSZlBDUqS0N3ufS1auAGE-zSGq5OgNQA6KL9hTp_AoH2T-Tf0GAUemTbyL7mRTSwV-RdkGikhtBCELC8Nb8OcAQoMBoCB5N15bA8sFotGjGtjTe2ka2eswdyYt2mPNlHn3a17-U9Cxlq5GqhweQG9WNyqZm24gSPb4DwWlGXEbsO5gviO50=s72-w640-h124-c" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-7565053925961886263</id><published>2025-10-20T20:30:00.001+02:00</published><updated>2025-10-20T20:30:28.715+02:00</updated><title type='text'>A lifting week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhDgibO_1ULeO5xqq6WFdU_iA1do4HJ4ahkpNQxWsG9-flN7KcMpQWMZkCt0ZQ7y76Hk_OgXz2NNBq8hVY6VLRQamVqPpImfTAdHpBf9gxUAsNpTFzFXqnWgcVXQjfO_B5SMIZwJfAYwi40Jokv_IRGRlfXaiw_w4Wcp4YmV9HUSqIkjIYgPzstjrvjoFU&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;244&quot; data-original-width=&quot;1089&quot; height=&quot;144&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhDgibO_1ULeO5xqq6WFdU_iA1do4HJ4ahkpNQxWsG9-flN7KcMpQWMZkCt0ZQ7y76Hk_OgXz2NNBq8hVY6VLRQamVqPpImfTAdHpBf9gxUAsNpTFzFXqnWgcVXQjfO_B5SMIZwJfAYwi40Jokv_IRGRlfXaiw_w4Wcp4YmV9HUSqIkjIYgPzstjrvjoFU=w640-h144&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The Universal Cup held its Stage 2: Paris during the Oct 6 - Oct 12 week (&lt;a href=&quot;https://contest.ucup.ac/contest/2551&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2551&quot;&gt;results&lt;/a&gt;, top 5 on the left). This was one of the very rare occassions where the winner seemingly was not a veteran team, but a team THU1 consisting of university students. They were already ahead of the usual suspects on 12 problems by penalty time, and solving the last problem 10 minutes before the end was the icing on the cake. Congratulations!&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgZgCXAEttnI-t2yNVg5FFTG6ikmswrzeHxW9Mq3gFQp2u-oQGixiUU_zLhEHcfkGzno_sxMK0Cju13Nl_tgFwlPIzdK_yaNw1qhj5uGC4ElpD7-00zTqAxkjnj2X-2mCS0z7ot_daNmojrWYj0OwhPaOmLGLgi0nVUsqUUUUweH-QCm3H-yWJdoTSIcas&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;278&quot; data-original-width=&quot;1106&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgZgCXAEttnI-t2yNVg5FFTG6ikmswrzeHxW9Mq3gFQp2u-oQGixiUU_zLhEHcfkGzno_sxMK0Cju13Nl_tgFwlPIzdK_yaNw1qhj5uGC4ElpD7-00zTqAxkjnj2X-2mCS0z7ot_daNmojrWYj0OwhPaOmLGLgi0nVUsqUUUUweH-QCm3H-yWJdoTSIcas=w640-h160&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Codeforces Round 1058 wrapped up the week on Sunday (&lt;a href=&quot;https://codeforces.com/contest/2159&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2159/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/147322&quot;&gt;analysis&lt;/a&gt;, &lt;a href=&quot;https://youtu.be/YyDY9a2xU2U&quot;&gt;my screencast&lt;/a&gt;). As the custom goes these days, I have started well on the easier problems but then got stuck, trying to make progress in either of the three remaining problems, and actually being close to solving D2 at the end, but not quite.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Nobody was able to solve everything this time, but the top 5 shows that many different strategies were competitive. In the end solving the problems fast from left to right was the winning recipe for Benq. Congratulations!&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIH71EaD1HWSbv86yAhO1BDAIouZ3W4Ts25juaxaiJS9R6Wlu16cpVA_cHbUizqQ4FlPEvogKG8xcsaVFLrM73EYi35PLzIjcNsKJBvAMM6LjN2UcehoEKbsO3kFO0Atxgskd34J5PXvhvkweDFRoZwFf0KkAkKY4899gofnJPh3TP0J2wzhOVldOplhU/s3514/PXL_20250815_124749631-EDIT.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;2308&quot; data-original-width=&quot;3514&quot; height=&quot;420&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIH71EaD1HWSbv86yAhO1BDAIouZ3W4Ts25juaxaiJS9R6Wlu16cpVA_cHbUizqQ4FlPEvogKG8xcsaVFLrM73EYi35PLzIjcNsKJBvAMM6LjN2UcehoEKbsO3kFO0Atxgskd34J5PXvhvkweDFRoZwFf0KkAkKY4899gofnJPh3TP0J2wzhOVldOplhU/w640-h420/PXL_20250815_124749631-EDIT.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In &lt;a href=&quot;https://blog.mitrichev.ch/2025/10/an-enough-week.html&quot;&gt;my previous summary&lt;/a&gt;, I have mentioned&amp;nbsp;&lt;a href=&quot;https://codeforces.com/contest/2152/problem/F&quot;&gt;another Codeforces problem&lt;/a&gt;: you are given &lt;i&gt;n&lt;/i&gt;&amp;lt;=250000 numbers which are written in sorted order. You need to process &lt;i&gt;q&lt;/i&gt;&amp;lt;=250000 queries, each query is a segment [&lt;i&gt;l&lt;/i&gt;, &lt;i&gt;r&lt;/i&gt;] of the numbers. For each query, you need to find the maximum amount of numbers within the segment&amp;nbsp;[&lt;i&gt;l&lt;/i&gt;, &lt;i&gt;r&lt;/i&gt;] that can be taken in such a way that for each three taken numbers the difference between the largest and the smallest of them is more than &lt;i&gt;z&lt;/i&gt;. The number &lt;i&gt;z&lt;/i&gt; is the same for all queries.&lt;p&gt;&lt;/p&gt;&lt;p&gt;The first step is solving the problem for a single [&lt;i&gt;l&lt;/i&gt;,&amp;nbsp;&lt;i&gt;r&lt;/i&gt;] query. It is not hard to convince oneself (if we want to have a formal proof, we can use the exchange argument) that we can do it greedily: take the first two numbers in the segment &lt;i&gt;a&lt;sub&gt;l&lt;/sub&gt;&lt;/i&gt; and &lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;+1&lt;/sub&gt;, then take the first number at position &lt;i&gt;l&lt;/i&gt;+2 or higher that is bigger than&amp;nbsp;&lt;i&gt;a&lt;sub&gt;l&lt;/sub&gt;&lt;/i&gt;+&lt;i&gt;z&lt;/i&gt;, then take the first number to the right of that that is bigger than&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;+1&lt;/sub&gt;+&lt;i&gt;z&lt;/i&gt;, and so on.&lt;/p&gt;&lt;p&gt;Now we need to learn to simulate this process fast so that we can process many queries with different values of &lt;i&gt;l&lt;/i&gt; within the time limit. The key observation is that the greedy solution can be split into two almost independent chains: the odd-numbered values are&amp;nbsp;&lt;i&gt;a&lt;sub&gt;l&lt;/sub&gt;&lt;/i&gt;, then the first number&amp;nbsp;&lt;i&gt;a&lt;sub&gt;k&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;that is bigger than&amp;nbsp;&lt;i&gt;a&lt;sub&gt;l&lt;/sub&gt;&lt;/i&gt;+&lt;i&gt;z&lt;/i&gt;, then the first number that is bigger than&amp;nbsp;&lt;i&gt;a&lt;sub&gt;k&lt;/sub&gt;&lt;/i&gt;+&lt;i&gt;z&lt;/i&gt;, and so on; and the even-numbered values are&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;+1&lt;/sub&gt;, the first number that is bigger that&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;+1&lt;/sub&gt;+&lt;i&gt;z&lt;/i&gt;, and so on. So a solution could count the numbers in those two chains independently and add the results up.&lt;/p&gt;&lt;p&gt;How do we count the numbers in one of those chains, starting with a given position&amp;nbsp;&lt;i&gt;a&lt;sub&gt;l&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;and until we pass&amp;nbsp;&lt;i&gt;a&lt;sub&gt;r&lt;/sub&gt;&lt;/i&gt;? This can be done using a standard algorithm called binary lifting: we can precompute where do we end up after we do 2&lt;sup&gt;&lt;i&gt;i&lt;/i&gt;&lt;/sup&gt; jumps from position &lt;i&gt;l&lt;/i&gt; for each &lt;i&gt;l&lt;/i&gt; and &lt;i&gt;i&lt;/i&gt;. Then to answer an [&lt;i&gt;l&lt;/i&gt;,&amp;nbsp;&lt;i&gt;r&lt;/i&gt;] query we first try to make 2&lt;sup&gt;&lt;i&gt;i&lt;/i&gt;&lt;/sup&gt;&amp;nbsp;jumps with the highest possible &lt;i&gt;i&lt;/i&gt;, if we overshoot&amp;nbsp;&lt;i&gt;a&lt;sub&gt;r&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;then we skip this step otherwise we take it, and then do the 2&lt;sup&gt;&lt;i&gt;i&lt;/i&gt;-1&lt;/sup&gt;&amp;nbsp;step, and so on. Since the true answer has a binary representation, we will find it in just O(log &lt;i&gt;n&lt;/i&gt;) steps per query, and the precomputation takes O(&lt;i&gt;n&lt;/i&gt;*log&amp;nbsp;&lt;i&gt;n&lt;/i&gt;).&lt;/p&gt;&lt;p&gt;However, this approach is not the full solution since the two chains are only &quot;almost&quot; independent. More specifically, it can happen that the arrive at the same position, and then one of the chains will instead take the next consecutive number as described above.&lt;/p&gt;&lt;p&gt;It turns out that for a given two starting positions &lt;i&gt;l&lt;/i&gt; and &lt;i&gt;l&lt;/i&gt;+1, we can again use binary lifting to find out when this happens! If two chains are at the same position at a certain moment, they will also be at the same position after any number of additional jumps. It means that we can still use the binary lifting idea of trying a large 2&lt;sup&gt;&lt;i&gt;i&lt;/i&gt;&lt;/sup&gt;&amp;nbsp;jump first for both chains, and if we are in the same position then we roll it back and try 2&lt;sup&gt;&lt;i&gt;i&lt;/i&gt;-1&lt;/sup&gt;, and so on.&lt;/p&gt;&lt;p&gt;Note that it is not necessarily true that the two chains will reach the same number at the same step, though. For example, it might happen that&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;+1&lt;/sub&gt;&amp;gt;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;&lt;/sub&gt;+&lt;i&gt;z&lt;/i&gt;, and then the first chain will have&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;+1&lt;/sub&gt;&amp;nbsp;at the second position. However, because the jump function is monotonic, the second chain will always be at the same position or to the right of it for the same step, and the first chain will always be at the same position or to the right of it when one step ahead of the second chain. So we just need to check those two possibilities (a collision at the same step, or a collision where the first chain is one step ahead) in the binary lifting condition.&lt;/p&gt;&lt;p&gt;This way we can precompute for all &lt;i&gt;n&lt;/i&gt; options for the starting position &lt;i&gt;l&lt;/i&gt;, where, and after how many jumps, do the chains starting from&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;&lt;/sub&gt;&amp;nbsp;and&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;+1&lt;/sub&gt;&amp;nbsp;collide. This precomputation takes O(&lt;i&gt;n&lt;/i&gt;*log&amp;nbsp;&lt;i&gt;n&lt;/i&gt;). Note that after the two chains collide, we now have the collision position &lt;i&gt;k&lt;/i&gt;, and the two chains continue from&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;k&lt;/i&gt;&lt;/sub&gt;&amp;nbsp;and&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;k&lt;/i&gt;+1&lt;/sub&gt;, so we have exactly the same situation as in the beginning.&lt;/p&gt;&lt;p&gt;Now we can consider a new type of jump, from&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;l&lt;/i&gt;&lt;/sub&gt;&amp;nbsp;to&amp;nbsp;&lt;i&gt;a&lt;/i&gt;&lt;sub&gt;&lt;i&gt;k&lt;/i&gt;&lt;/sub&gt;&amp;nbsp;as described above, and do binary lifting on those big jumps! This time we need to precompute two things for each &lt;i&gt;l&lt;/i&gt; and &lt;i&gt;i&lt;/i&gt;: where do we end up after 2&lt;sup&gt;&lt;i&gt;i&lt;/i&gt;&lt;/sup&gt;&amp;nbsp;big jumps, and how many small jumps does that entail.&lt;/p&gt;&lt;p&gt;And finally to correctly answer an [&lt;i&gt;l&lt;/i&gt;,&amp;nbsp;&lt;i&gt;r&lt;/i&gt;] query, we first do the binary lifting steps using big jumps from&amp;nbsp;&lt;i&gt;a&lt;sub&gt;l&lt;/sub&gt;&lt;/i&gt;, and as soon as the next big jump would overshoot&amp;nbsp;&lt;i&gt;a&lt;sub&gt;r&lt;/sub&gt;&lt;/i&gt;, we do the binary lifting steps using small jumps for the remainder.&lt;/p&gt;&lt;p&gt;The solution was ultimately about applying a standard algorithm three times, not about coming up with a novel approach. However, I still find it quite beautiful how the same idea just keeps on giving.&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back for last week&#39;s summary!&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/7565053925961886263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/10/a-lifting-week.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/7565053925961886263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/7565053925961886263'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/10/a-lifting-week.html' title='A lifting week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhDgibO_1ULeO5xqq6WFdU_iA1do4HJ4ahkpNQxWsG9-flN7KcMpQWMZkCt0ZQ7y76Hk_OgXz2NNBq8hVY6VLRQamVqPpImfTAdHpBf9gxUAsNpTFzFXqnWgcVXQjfO_B5SMIZwJfAYwi40Jokv_IRGRlfXaiw_w4Wcp4YmV9HUSqIkjIYgPzstjrvjoFU=s72-w640-h144-c" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-437033860430065129</id><published>2025-10-09T22:00:00.001+02:00</published><updated>2025-10-09T22:00:24.469+02:00</updated><title type='text'>An enough week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhqCyIAIF1oCGVhI0_76kLDrpSUZLhBH23s6QrfHvyQkPQDqiZe9ow9OHxj9T1KiPrgvDY0XtKnBwxbMkeEeRDDP89gtUB21cbJ0RQH1d1IJFQ1uKEvBUvoOxUMWMeFZaYRLRBPrZs-1Bv715Y2iEr1lFs8BRNHXz9wxc78omc5oQSxMaboAgKeOKiyic0&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;279&quot; data-original-width=&quot;1106&quot; height=&quot;162&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhqCyIAIF1oCGVhI0_76kLDrpSUZLhBH23s6QrfHvyQkPQDqiZe9ow9OHxj9T1KiPrgvDY0XtKnBwxbMkeEeRDDP89gtUB21cbJ0RQH1d1IJFQ1uKEvBUvoOxUMWMeFZaYRLRBPrZs-1Bv715Y2iEr1lFs8BRNHXz9wxc78omc5oQSxMaboAgKeOKiyic0=w640-h162&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Squarepoint Challenge, also known as Codeforces Round 1055, was the first event of last week (&lt;a href=&quot;https://codeforces.com/contest/2152&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2152/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/146988&quot;&gt;analysis&lt;/a&gt;). This round followed a different &lt;a href=&quot;https://codeforces.com/blog/entry/146878?#comment-1314259&quot;&gt;problemsetting philosophy&lt;/a&gt;, so for me it was mostly about figuring out the best way to implement a solution and actually implementing it, as I got the general idea for solving each problem, including H2, fairly quickly. Unfortunately, I got bogged down with the details of F for almost a whole hour, which meant I could not really compete for the top spots.&lt;p&gt;&lt;/p&gt;&lt;p&gt;Nachia, on the other hand, was one of the fastest on the first 8 problems and managed to figure out the implementation of H2 with almost half an hour to spare. Congratulations on the victory!&lt;/p&gt;&lt;p&gt;Here is that &lt;a href=&quot;https://codeforces.com/contest/2152/problem/F&quot;&gt;problem F&lt;/a&gt; that delayed me: you are given &lt;i&gt;n&lt;/i&gt;&amp;lt;=250000 numbers which are written in sorted order. You need to process &lt;i&gt;q&lt;/i&gt;&amp;lt;=250000 queries, each query is a segment [&lt;i&gt;l&lt;/i&gt;, &lt;i&gt;r&lt;/i&gt;] of the numbers. For each query, you need to find the maximum amount of numbers within the segment&amp;nbsp;[&lt;i&gt;l&lt;/i&gt;, &lt;i&gt;r&lt;/i&gt;] that can be taken in such a way that for each three taken numbers the difference between the largest and the smallest of them is more than &lt;i&gt;z&lt;/i&gt;. The number &lt;i&gt;z&lt;/i&gt; is the same for all queries. Can you see how to combine the standard building blocks to obtain a solution here?&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjmZlI4nNS3IW2tZDbMTM1P43M9R7IHFD4122OYXVIYUcv-O_IzFfiV3CDP-VtQwKio216NGpc3C4ZfDdtcXFZmejg2ApSab5uIz7oxRfVwpX3dnwvZMSqz0VQZntCmoxzpHJ15EZYGu38r2b0bAIPM4zqPE9sYPlsJGtsyg8lqi3btEglNenGuOQqopWM&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;229&quot; data-original-width=&quot;1001&quot; height=&quot;146&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjmZlI4nNS3IW2tZDbMTM1P43M9R7IHFD4122OYXVIYUcv-O_IzFfiV3CDP-VtQwKio216NGpc3C4ZfDdtcXFZmejg2ApSab5uIz7oxRfVwpX3dnwvZMSqz0VQZntCmoxzpHJ15EZYGu38r2b0bAIPM4zqPE9sYPlsJGtsyg8lqi3btEglNenGuOQqopWM=w640-h146&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The Universal Cup opened its 4th season with Stage 1: Korolyov (&lt;a href=&quot;https://contest.ucup.ac/contest/2539&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2539&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://contest.ucup.ac/download.php?type=attachments&amp;amp;id=2539&amp;amp;r=1&quot;&gt;analysis&lt;/a&gt;). The usual suspects USA1 were only the third team to solve everything, but they were much faster on the easy problems and won with much lower total penalty time. Congratulations to them and to the teams THU1, PKU1 and&amp;nbsp;HoMaMaOvO who also solved 11!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgStCn_6NVpNGUwDHO3i_KVWT9fCQzwk8FNF0Tc-dPt3Vlt1RAmUwPAbOv4tXptkYZgh05FJEy89jcDpkXnUlwLmpMZanagAfRXELdu2rW1k-ePXWuJEv5XvKkit_A5V2xznk-q1YjBE8h3J1C1sZWpNMwaeoJB35PDwP_mwEnFWAxalpetI8jakT_FnBw/s4080/PXL_20250826_131723640.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgStCn_6NVpNGUwDHO3i_KVWT9fCQzwk8FNF0Tc-dPt3Vlt1RAmUwPAbOv4tXptkYZgh05FJEy89jcDpkXnUlwLmpMZanagAfRXELdu2rW1k-ePXWuJEv5XvKkit_A5V2xznk-q1YjBE8h3J1C1sZWpNMwaeoJB35PDwP_mwEnFWAxalpetI8jakT_FnBw/w640-h482/PXL_20250826_131723640.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In &lt;a href=&quot;https://blog.mitrichev.ch/2025/10/a-grand-week.html&quot;&gt;my previous summary&lt;/a&gt;, I have mentioned two problems. The first one (&lt;a href=&quot;https://codeforces.com/contest/2150/problem/E1&quot;&gt;E1&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2150/problem/E2&quot;&gt;E2&lt;/a&gt;) came from Codeforces: there is a hidden array of size 2&lt;i&gt;n&lt;/i&gt;-1, where each number between 1 and &lt;i&gt;n&lt;/i&gt; appears twice, except one which only appears once, and you need to find out which one. To do that, you can only ask queries of the following form: choose a collection of indices in the array, and a number between 1 and &lt;i&gt;n&lt;/i&gt;, and you will be told if this number appears at at least one of those indices in the array.&lt;p&gt;&lt;/p&gt;&lt;p&gt;In E1, we have &lt;i&gt;n&lt;/i&gt;&amp;lt;=300 and you need to find the answer using at most 4&lt;i&gt;n&lt;/i&gt;+2*ceil(log&lt;sub&gt;2&lt;/sub&gt;&lt;i&gt;n&lt;/i&gt;) queries. In E2, we have &lt;i&gt;n&lt;/i&gt;=300 exactly and you need to find the answer using at most 925 queries.&lt;/p&gt;&lt;p&gt;Having &lt;i&gt;n&lt;/i&gt;=300 instead of &lt;i&gt;n&lt;/i&gt;&amp;lt;=300 in E2 strongly hints that the expected solution is randomized, while the 4&lt;i&gt;n&lt;/i&gt;+2*ceil(log&lt;sub&gt;2&lt;/sub&gt;&lt;i&gt;n&lt;/i&gt;) formula in E1 most likely promises a deterministic one. So the two problems with the same story would seem almost independent in terms of their solutions.&lt;/p&gt;&lt;p&gt;There is a building block that is shared between the solutions, and it is somewhat natural: let us split the entire array into two parts, and ask if a given number appears in each of those parts.&lt;/p&gt;&lt;p&gt;It is easier to see how to make a randomized solution out of this building block: if we know that a number appears in both parts, then it cannot be the answer, as it must have two occurrences. Moreover, if we choose the parts randomly, then with probability around 1/2 the two occurrences will end up in different parts and we will exclude this number from the candidates for the answer. And this, in turn, means that after 1/(1/2)=2 attempts on average we will exclude each number that is not the answer, so after around 2&lt;i&gt;n&lt;/i&gt; total attempts we will have only one number remaining which we can return (this is not exactly the case as we will also spend attempts on the number that is in fact the answer, so effectively the least lucky sequence gets multiplied by 2, but this change only adds a logarithmic term to the expected total). Given that each attempt takes 2 queries, we will spend around 4&lt;i&gt;n&lt;/i&gt; queries on average, which is too much as 4*300=1200&amp;gt;925.&lt;/p&gt;&lt;p&gt;On a more careful examination, we can notice that we don&#39;t always need 2 queries per attempt. If we got the answer that the first part does not have the number, we do not need to ask about the second part as we know it is there. So on failed attempts (that have both occurrences in one part) we will spend only 1.5 queries on avereage, while on successful attempts we will spend 2. The number of failed attempts is 2-1=1 per number on average, so we will spend around 3.5&lt;i&gt;n&lt;/i&gt; queries in total, which is still a bit too much as 3.5*300=1050&amp;gt;925.&lt;/p&gt;&lt;p&gt;Let us put E2 aside for a moment and return to E1. How can we make a deterministic solution out of the same building block? Well, let us fix the split into two parts, and ask for all numbers if they appear in each of the two parts. We spent 2&lt;i&gt;n&lt;/i&gt; queries on this, and all numbers are split into three categories: appearing only in the first part, only in the second part, or in both. The key observation here is that by comparing the parity of the size of a part with the parity of the amount of numbers that appear in both parts (and therefore have 1 occurrence in each part) we can tell if the answer, the only number that appears in one part but only once, is in this part or not. This way we have reduced the problem to one with twice smaller size, but now we also have some numbers that are known to appear only once.&lt;/p&gt;&lt;p&gt;We can now apply the same idea recursively to the smaller problem, with the small optimization that for numbers that are known to appear only once, we need only one query to figure out which of the two parts does it belong to. Since we spend two queries for a number that appears twice or for the answer and one query for a number that is known to appear once, the total number of queries to split a part in two is always the size of the part plus one. So the total number of queries we need is roughly 2&lt;i&gt;n&lt;/i&gt;+&lt;i&gt;n&lt;/i&gt;+&lt;i&gt;n&lt;/i&gt;/2+... ~= 4&lt;i&gt;n&lt;/i&gt;, so we have solved E1.&lt;/p&gt;&lt;p&gt;Returning to E2, we need to notice that the first step of our solution for E1 is quite efficient: we spend 2&lt;i&gt;n&lt;/i&gt; queries, and on average we will have only &lt;i&gt;n&lt;/i&gt;/4 candidates left after it, so we eliminate 3&lt;i&gt;n&lt;/i&gt;/4 candidates in 2&lt;i&gt;n&lt;/i&gt; queries, 8/3 queries per candidate on average, and 8/3 is much less than 3.5 which was our average before. We cannot be as efficient in subsequent steps (because we also have to deal with numbers that are known to appear once), but we do not need to: applying the naive randomized solution which spends 3.5 queries per candidate for the remaining &lt;i&gt;n&lt;/i&gt;/4 candidates yields 7&lt;i&gt;n&lt;/i&gt;/8 queries, so the total number of queries is 2&lt;i&gt;n&lt;/i&gt;+7&lt;i&gt;n&lt;/i&gt;/8=23&lt;i&gt;n&lt;/i&gt;/8, which for n=300 gives&amp;nbsp;862.5, well below the allowed amount. This solves E2.&lt;/p&gt;&lt;p&gt;I find the different yet interconnected solutions for the two variants of the problem quite beautiful.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSqgNmPGlFkGdyPv1R6uD0FdzwKbninR5ap8XOH7lv6snhEE-jZsP7aj-C7lDLXpFUBQBXd2c81E44WqXS7VbIEUeXLEYRdbhAeXedxcquRbucimAhCE9dZfHCMbfI0cREHiYR-og1jmZl-WTOGS4bUGKJUDNO3pq4jfUNf-Oy3JjbOgOTSA5CCNRWSsw/s4080/PXL_20250810_095146304.MP.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4080&quot; data-original-width=&quot;3072&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSqgNmPGlFkGdyPv1R6uD0FdzwKbninR5ap8XOH7lv6snhEE-jZsP7aj-C7lDLXpFUBQBXd2c81E44WqXS7VbIEUeXLEYRdbhAeXedxcquRbucimAhCE9dZfHCMbfI0cREHiYR-og1jmZl-WTOGS4bUGKJUDNO3pq4jfUNf-Oy3JjbOgOTSA5CCNRWSsw/w482-h640/PXL_20250810_095146304.MP.jpg&quot; width=&quot;482&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href=&quot;https://atcoder.jp/contests/agc073/tasks/agc073_c&quot;&gt;The second one&lt;/a&gt;&amp;nbsp;came from AtCoder: you are given a tree with &lt;i&gt;n&lt;/i&gt;&amp;lt;=5000 vertices. We choose a real weight &lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; for each vertex &lt;i&gt;i&lt;/i&gt; from the range [-&lt;i&gt;n&lt;/i&gt;+1,1] independently and unformly at random. Now, for each vertex &lt;i&gt;i&lt;/i&gt; we compute&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;as the highest sum of weights in a connected subtree containing vertex &lt;i&gt;i&lt;/i&gt;. Now we define the score of the tree as follows: if for all &lt;i&gt;i&lt;/i&gt; we have 0&amp;lt;=&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=1, then the score is equal to the product of all&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;, otherwise it is 0. You need to find the expected value of the score.&lt;p&gt;&lt;/p&gt;&lt;p&gt;First, let us look at the connected subtree &lt;i&gt;B&lt;/i&gt; with the maximum sum of weights among all connected subtrees. All vertices in this subtree have the same value of&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=&lt;i&gt;y&lt;/i&gt;. Let us choose one of those vertices and root the tree from that vertex. Now suppose we run the standard dynamic programming that computes for each subtree the highest sum of weights in a connected subtree containing the root of that subtree, with the very straightforward transition of &lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;+sum(max(0, &lt;i&gt;dp&lt;sub&gt;j&lt;/sub&gt;&lt;/i&gt;)) over all children &lt;i&gt;j&lt;/i&gt; of &lt;i&gt;i&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;For each vertex &lt;i&gt;i&lt;/i&gt; in our best subtree&amp;nbsp;&lt;i&gt;B&lt;/i&gt;&amp;nbsp;we have the following constraints:&amp;nbsp;&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=&lt;i&gt;y&lt;/i&gt;&amp;nbsp;(since otherwise we have a connected subtree with value more than &lt;i&gt;y&lt;/i&gt;, which is a contradiction to the choice of &lt;i&gt;y&lt;/i&gt;), and&amp;nbsp;&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;gt;=0 (since otherwise we can remove &lt;i&gt;y&lt;/i&gt; together with its subtree from &lt;i&gt;B&lt;/i&gt; to obtain another connected subtree with a higher value). Additionally, for the root of &lt;i&gt;B&lt;/i&gt; we must have&amp;nbsp;&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=&lt;i&gt;y&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;It turns out that those conditions are not just necessary, but sufficient! If for all vertices &lt;i&gt;i&lt;/i&gt; in &lt;i&gt;B&lt;/i&gt; we have 0&amp;lt;=&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=&lt;i&gt;y&lt;/i&gt;, and for the root&amp;nbsp;&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=&lt;i&gt;y&lt;/i&gt;, then for all vertices &lt;i&gt;i&lt;/i&gt; in &lt;i&gt;B&lt;/i&gt;&amp;nbsp;we have &lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=&lt;i&gt;y&lt;/i&gt;. We can see this by looking at how an arbitrary connected subtree intersects with &lt;i&gt;B&lt;/i&gt;, and realizing that since&amp;nbsp;&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;gt;=0, we can always add more vertices of &lt;i&gt;B&lt;/i&gt; to the subtree without decreasing its value until the intersection becomes a subtree of &lt;i&gt;B&lt;/i&gt;, and then its value is bounded by&amp;nbsp;&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=&lt;i&gt;y&lt;/i&gt;&amp;nbsp;so we can further augment the intersection to the full &lt;i&gt;B&lt;/i&gt; without decreasing the value.&lt;/p&gt;&lt;p&gt;Now suppose we choose the values of&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;as we run this dynamic programming. Then no matter what are the values of&amp;nbsp;&lt;i&gt;dp&lt;sub&gt;j&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;for vertices &lt;i&gt;j&lt;/i&gt; not in &lt;i&gt;B&lt;/i&gt;, for each vertex &lt;i&gt;i&lt;/i&gt; that is in &lt;i&gt;B&lt;/i&gt; but is not its root we will have a range of values&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&amp;nbsp;&lt;/sub&gt;&lt;/i&gt;of length exactly&amp;nbsp;&lt;i&gt;y&lt;/i&gt;&amp;nbsp;(out of the overall range [-&lt;i&gt;n&lt;/i&gt;+1,1] of length &lt;i&gt;n&lt;/i&gt;) that will yield 0&amp;lt;=&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=&lt;i&gt;y&lt;/i&gt;, and for the root there will be exactly one value of&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;that yields&amp;nbsp;&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=&lt;i&gt;y&lt;/i&gt;. This means that we can compute the probability density for&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=&lt;i&gt;y&lt;/i&gt;&amp;nbsp;in &lt;i&gt;B&lt;/i&gt; as a function of&amp;nbsp;&lt;i&gt;y&lt;/i&gt; that is independent from what happens outside of &lt;i&gt;B&lt;/i&gt;: it is simply &lt;i&gt;y&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;-1&lt;/sup&gt;/&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;&lt;/sup&gt;, where &lt;i&gt;b&lt;/i&gt; is the number of vertices in &lt;i&gt;B&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Now let us look at the connected subtree &lt;i&gt;C&lt;/i&gt; with the highest value that contains at least one vertex outside of &lt;i&gt;B&lt;/i&gt;. All vertices of &lt;i&gt;C&lt;/i&gt; that are not in &lt;i&gt;B&lt;/i&gt; have the same value of&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=z, and we can assume that those vertices form a connecteded subtree themselves. Indeed, suppose removing &lt;i&gt;B&lt;/i&gt; splits &lt;i&gt;C&lt;/i&gt; into multiple independent parts. Since &lt;i&gt;B&lt;/i&gt; is the subtree with the highest sum, each of those parts must have a non-positive sum, otherwise we could improve &lt;i&gt;B&lt;/i&gt;. But then we can remove all but one of those parts and obtain a new &lt;i&gt;C&lt;/i&gt; with at least as high value of z that is in one piece. So there are essentially two choices to consider: either &lt;i&gt;C&lt;/i&gt; is disjoint with &lt;i&gt;B&lt;/i&gt;, or &lt;i&gt;C&lt;/i&gt; contains the entire&amp;nbsp;&lt;i&gt;B&lt;/i&gt;&amp;nbsp;plus some other connected subtree.&lt;/p&gt;&lt;p&gt;Then we can apply exactly the same approach as we did for &lt;i&gt;B&lt;/i&gt; and prove that the probability density for each vertex in &lt;i&gt;C&lt;/i&gt;-&lt;i&gt;B&lt;/i&gt; having&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;=z is simply&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&lt;sup&gt;&lt;i&gt;c&lt;/i&gt;-1&lt;/sup&gt;/&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;&lt;i&gt;c&lt;/i&gt;&lt;/sup&gt;, and we additionally know that &lt;i&gt;z&lt;/i&gt;&amp;lt;=&lt;i&gt;y&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;We can keep applying the same step until the entire tree is split into connected components with the same values of&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;, with the probability density of that happenning being a product of terms of the form&amp;nbsp;&lt;i&gt;y&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;-1&lt;/sup&gt;/&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;&lt;/sup&gt;&amp;nbsp;and some constraints of the form&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;lt;=&lt;i&gt;y&lt;/i&gt;. And here comes another crucial observation: we can forget about the constraints of the form&amp;nbsp;&lt;i&gt;z&lt;/i&gt;&amp;lt;=&lt;i&gt;y&lt;/i&gt;! Since when &lt;i&gt;z&lt;/i&gt;&amp;gt;&lt;i&gt;y&lt;/i&gt;, we can still obtain this structure, just taking the component with &lt;i&gt;z&lt;/i&gt; before he component with &lt;i&gt;y&lt;/i&gt;. So in effect, we just need to split the tree into connected parts, and then we can handle the parts completely independently, with the only constraint being 0&amp;lt;=&lt;i&gt;y&lt;/i&gt;&amp;lt;=1.&lt;/p&gt;&lt;p&gt;The product of&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;for all &lt;i&gt;i&lt;/i&gt; in &lt;i&gt;B&lt;/i&gt;&amp;nbsp;is equal to &lt;i&gt;y&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;&lt;/sup&gt;, and its expected value is therefore equal to the integral of&amp;nbsp;&lt;i&gt;y&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;&lt;/sup&gt;*&lt;i&gt;y&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;-1&lt;/sup&gt;/&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;&lt;/sup&gt;&amp;nbsp;over 0&amp;lt;=&lt;i&gt;y&lt;/i&gt;&amp;lt;=1, which is equal to 1/(2*b*&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;&lt;/sup&gt;). The expected value of a product is equal to the product of expected values for independent random variables, and we already established that we can treat &lt;i&gt;y&lt;/i&gt;, &lt;i&gt;z&lt;/i&gt;, ... independently. So we just need to find the sum of products of 1/(2*b*&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;&lt;i&gt;b&lt;/i&gt;&lt;/sup&gt;) for all possible ways to split a tree into connected subtrees, which is solved with a standard dynamic programming on the tree that remembers the size of &quot;running&quot; part containing the root of the subtree in its state, and runs in O(&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;2&lt;/sup&gt;) since the sum of products of sizes of children being merged in such DP for any tree is O(&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;2&lt;/sup&gt;), in turn since every pair of vertices merge into one subtree only once.&lt;/p&gt;&lt;p&gt;From another angle, we have &quot;reordered the summation&quot; in this solution two times: first, we decide on the values of&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;, and then we decide on the values of&amp;nbsp;&lt;i&gt;dp&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;, and only then we obtain the values of&amp;nbsp;&lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;which are the original random variables.&lt;/p&gt;&lt;p&gt;I find this solution quite beautiful as it requires creating a deep understanding of the structure induced by the process described in the problem statement, and this structure ends up being non-trivial yet tractable. Well done to the problemsetters!&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back next week.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/437033860430065129/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/10/an-enough-week.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/437033860430065129'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/437033860430065129'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/10/an-enough-week.html' title='An enough week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhqCyIAIF1oCGVhI0_76kLDrpSUZLhBH23s6QrfHvyQkPQDqiZe9ow9OHxj9T1KiPrgvDY0XtKnBwxbMkeEeRDDP89gtUB21cbJ0RQH1d1IJFQ1uKEvBUvoOxUMWMeFZaYRLRBPrZs-1Bv715Y2iEr1lFs8BRNHXz9wxc78omc5oQSxMaboAgKeOKiyic0=s72-w640-h162-c" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-8625640425495730901</id><published>2025-10-05T15:24:00.001+02:00</published><updated>2025-10-05T15:24:45.984+02:00</updated><title type='text'>A grand week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjER9rfYq6LcG4xcRmTf9X1dH5lYxr6NZVtgTXYEzEx-Wx3oW1FiQ3RSiVe2vGrdiS9bJ9oxSe9-k8QtN4NTkVbSbAMaIoxm0eyT4YxlErK4Le_mW2xpY-R7MI6IBC7cjDWKN9_78t71G_16u2lgSH67CJ2n55c3kGJTVKojBguPDgFT2kHJ_IbyZ0fkwQ&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;279&quot; data-original-width=&quot;1102&quot; height=&quot;162&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjER9rfYq6LcG4xcRmTf9X1dH5lYxr6NZVtgTXYEzEx-Wx3oW1FiQ3RSiVe2vGrdiS9bJ9oxSe9-k8QtN4NTkVbSbAMaIoxm0eyT4YxlErK4Le_mW2xpY-R7MI6IBC7cjDWKN9_78t71G_16u2lgSH67CJ2n55c3kGJTVKojBguPDgFT2kHJ_IbyZ0fkwQ=w640-h162&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;After a bit of a summer lull the contests are starting to gain steam again. Last week started with the Codeforces Round 1053 on Wednesday (&lt;a href=&quot;https://codeforces.com/contest/2150&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2150/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/146651&quot;&gt;analysis&lt;/a&gt;). I got stuck in the implementation details of problem D for almost a full hour, then spent some time implementing a local tester for E2 to see how far my solution for E1 was from solving E2 (quite far) and trying to improve it by replacing binary search with ternary (only made it worse), and therefore when I opened problem F and got the right idea almost immediately (use length 2 in the first step, consider the diameter in the second step to reduce the problem to one on the line) I could not finish the implementation in time, even though 15 minutes were added to the contest duration. Some quite usual scenes for me these days :)&lt;p&gt;&lt;/p&gt;&lt;p&gt;It was usual scenes for Kevin as well, only for him it meant solving F much faster than everybody else and getting the first place by a margin. Congratulations!&lt;/p&gt;&lt;p&gt;I would like to highlight the interactive problem E (&lt;a href=&quot;https://codeforces.com/contest/2150/problem/E1&quot;&gt;E1&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2150/problem/E2&quot;&gt;E2&lt;/a&gt;) from this round: there is a hidden array of size 2&lt;i&gt;n&lt;/i&gt;-1, where each number between 1 and &lt;i&gt;n&lt;/i&gt; appears twice, except one which only appears once, and you need to find out which one. To do that, you can only ask queries of the following form: choose a collection of indices in the array, and a number between 1 and &lt;i&gt;n&lt;/i&gt;, and you will be told if this number appears at at least one of those indices in the array. In E1, we have &lt;i&gt;n&lt;/i&gt;&amp;lt;=300 and you need to find the answer using at most 4&lt;i&gt;n&lt;/i&gt;+2*ceil(log&lt;sub&gt;2&lt;/sub&gt;&lt;i&gt;n&lt;/i&gt;) queries. In E2, we have &lt;i&gt;n&lt;/i&gt;=300 exactly and you need to find the answer using at most 925 queries. What do those differences in constraints tell you?&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg7LmFAIYKGwBIIDnID9fCZEnFrgGztcPnItpvA9ZkvMvUp1STHDFOR4TMrBrhhEc5JX6V4JXENpJXH4URColbOiz1vLXINNEI4v0PFQtFZq_bF3U5iIUIKXe2lZOlZDjjm-sqScqBef54dwza8E3zG9nHObkx_Is9178cODde4cACdraWL1tMXWr-w_aE&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;330&quot; data-original-width=&quot;811&quot; height=&quot;260&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg7LmFAIYKGwBIIDnID9fCZEnFrgGztcPnItpvA9ZkvMvUp1STHDFOR4TMrBrhhEc5JX6V4JXENpJXH4URColbOiz1vLXINNEI4v0PFQtFZq_bF3U5iIUIKXe2lZOlZDjjm-sqScqBef54dwza8E3zG9nHObkx_Is9178cODde4cACdraWL1tMXWr-w_aE=w640-h260&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;AtCoder Grand Contest 073 on Sunday brought another AI story (&lt;a href=&quot;https://atcoder.jp/contests/agc073/tasks&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://atcoder.jp/contests/agc073/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://atcoder.jp/contests/agc073/editorial&quot;&gt;analysis&lt;/a&gt;). I got off to a good start by solving A faster than everyone in the screenshot on the left, but the remaining 2.5 hours of the round were not very productive. I felt that I was quite close on B and I kept updating my solution to handle yet another counterexample found by the stress test, but I failed to generalize and to notice that one of the corner cases in my wrong solution could be made into a correct solution.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;tour1st has solved that same B in just over 8 minutes, and got the three solvable problems done almost half an hour before everybody else. Congratulations on the win!&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The big story of this round was of course &lt;a href=&quot;https://atcoder.jp/posts/1564&quot;&gt;this announcement&lt;/a&gt;&amp;nbsp;(some &lt;a href=&quot;https://codeforces.com/blog/entry/146815?#comment-1313207&quot;&gt;reactions&lt;/a&gt;), which was followed up by &lt;a href=&quot;https://atcoder.jp/posts/1568&quot;&gt;this rule change&lt;/a&gt;. AtCoder Grand Contest was the last place where using AI was explicitly allowed and even encouraged, hoping to discover new creative ways to use AI to improve the humans&#39; problem solving ability. However, in this round it turned out that AI can solve problem C without human help, and this was the last straw that made AtCoder admins disallow the use of AI in AGC going forward, to avoid the contest turning into a prompting competition, and into a &quot;who has money to pay for access to a better model&quot; competition.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here is that fateful &lt;a href=&quot;https://atcoder.jp/contests/agc073/tasks/agc073_c&quot;&gt;problem C&lt;/a&gt;: you are given a tree with &lt;i&gt;n&lt;/i&gt;&amp;lt;=5000 vertices. We choose a real weight &lt;i&gt;a&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt; for each vertex &lt;i&gt;i&lt;/i&gt; from the range [-&lt;i&gt;n&lt;/i&gt;+1,1] independently and unformly at random. Now, for each vertex &lt;i&gt;i&lt;/i&gt; we compute&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;nbsp;as the highest sum of weights in a connected subtree containing vertex &lt;i&gt;i&lt;/i&gt;. Now we define the score of the tree as follows: if for all &lt;i&gt;i&lt;/i&gt; we have 0&amp;lt;=&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;&amp;lt;=1, then the score is equal to the product of all&amp;nbsp;&lt;i&gt;x&lt;sub&gt;i&lt;/sub&gt;&lt;/i&gt;, otherwise it is 0. You need to find the expected value of the score. Can you keep up with AI here?&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back later for this week&#39;s summary!&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/8625640425495730901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/10/a-grand-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/8625640425495730901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/8625640425495730901'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/10/a-grand-week.html' title='A grand week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjER9rfYq6LcG4xcRmTf9X1dH5lYxr6NZVtgTXYEzEx-Wx3oW1FiQ3RSiVe2vGrdiS9bJ9oxSe9-k8QtN4NTkVbSbAMaIoxm0eyT4YxlErK4Le_mW2xpY-R7MI6IBC7cjDWKN9_78t71G_16u2lgSH67CJ2n55c3kGJTVKojBguPDgFT2kHJ_IbyZ0fkwQ=s72-w640-h162-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-1433744362842150453</id><published>2025-09-22T20:52:00.002+02:00</published><updated>2025-09-22T20:52:57.489+02:00</updated><title type='text'>A skipped week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgegHJ6qHIJjqqHgF_KhSuV6gNg57iolyvEm7bXh-mDLoHT-O9l8HzOQZEcp0vCQmwF5UeWs-B2ULUtDSC5BFdGL5Bnx0QIrYsorrxAku1pCOdn3UZhrR8dlPAQq5FvuBzCYN-12qFYmU-RHFJCJ4T1AkMuGf_Jmo0Q7Y16WQTV1xEZFb10LURk3t7tPuU/s1100/Screenshot%202025-09-22%20200158.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;276&quot; data-original-width=&quot;1100&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgegHJ6qHIJjqqHgF_KhSuV6gNg57iolyvEm7bXh-mDLoHT-O9l8HzOQZEcp0vCQmwF5UeWs-B2ULUtDSC5BFdGL5Bnx0QIrYsorrxAku1pCOdn3UZhrR8dlPAQq5FvuBzCYN-12qFYmU-RHFJCJ4T1AkMuGf_Jmo0Q7Y16WQTV1xEZFb10LURk3t7tPuU/w640-h160/Screenshot%202025-09-22%20200158.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Codeforces Global Round 29 was the main event of last week (&lt;a href=&quot;https://codeforces.com/contest/2147&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2147/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/146633&quot;&gt;analysis&lt;/a&gt;). Only 3 participants managed to solve the 5500-point problem H, and they occupied the first three spots. Well done to ecnerwala, jiangly and ksun48!&lt;p&gt;&lt;/p&gt;&lt;p&gt;The big story of the round though was the solve count for problem G. According to the screenshot in &lt;a href=&quot;https://codeforces.com/blog/entry/146629&quot;&gt;this post&lt;/a&gt;&amp;nbsp;the solve count was at 184+ when the round ended, while the final standings had just 48, so 136+ solutions were removed because of cheating. The two most likely types of cheating would be &lt;a href=&quot;https://codeforces.com/blog/entry/133941&quot;&gt;using AI to solve the problem&lt;/a&gt;&amp;nbsp;and getting help from other people. Of course, one could also use both :) I saw speculations about both types happening in this case, but I am not sure if there is any public analysis on which type dominated this time. Have you seen one? The raw data on the solutions deemed to be cheating seems available in &lt;a href=&quot;https://codeforces.com/contest/2147/status/page/1?order=BY_JUDGED_DESC&quot;&gt;this search&lt;/a&gt; (it has 200+ solutions though, so maybe it overcounts?).&lt;/p&gt;&lt;p&gt;Of course, huge thanks to the Codeforces admins for trawling through the submissions and taking action to preserve the integrity of the competition! Before this case I somehow expected the number of cheating disqualifications to be much lower, even though I have seen numerous discussions of the issue. Would this push the competitive programming world to have more onsite contests with no internet access?&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back next week!&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/1433744362842150453/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/09/a-skipped-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/1433744362842150453'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/1433744362842150453'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/09/a-skipped-week.html' title='A skipped week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgegHJ6qHIJjqqHgF_KhSuV6gNg57iolyvEm7bXh-mDLoHT-O9l8HzOQZEcp0vCQmwF5UeWs-B2ULUtDSC5BFdGL5Bnx0QIrYsorrxAku1pCOdn3UZhrR8dlPAQq5FvuBzCYN-12qFYmU-RHFJCJ4T1AkMuGf_Jmo0Q7Y16WQTV1xEZFb10LURk3t7tPuU/s72-w640-h160-c/Screenshot%202025-09-22%20200158.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-679791212938586059</id><published>2025-09-14T23:05:00.000+02:00</published><updated>2025-09-14T23:05:14.219+02:00</updated><title type='text'>A Kevin week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJDFxcC0BTVFfZLE0XEhyphenhyphenYYXKgGbaiFqcf7Stsi0QTLjadUVU29OTNU0krbPAynTwu73229uw9BWQa-Ee89lcfACTkWYFHQLRhCEHDABCVZ4Cmy545Fv9KA3e44fIFMBzAzOA56nAfSnP7H3LVBmljsCoutc1PQVvmEhMvnoeqB44gIqSMJkZ9A89WnXU/s1102/Screenshot%202025-09-14%20102618.png&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;273&quot; data-original-width=&quot;1102&quot; height=&quot;159&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJDFxcC0BTVFfZLE0XEhyphenhyphenYYXKgGbaiFqcf7Stsi0QTLjadUVU29OTNU0krbPAynTwu73229uw9BWQa-Ee89lcfACTkWYFHQLRhCEHDABCVZ4Cmy545Fv9KA3e44fIFMBzAzOA56nAfSnP7H3LVBmljsCoutc1PQVvmEhMvnoeqB44gIqSMJkZ9A89WnXU/w640-h159/Screenshot%202025-09-14%20102618.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Codeforces Round 1048 on Monday was the first competition of this week (&lt;a href=&quot;https://codeforces.com/contest/2138&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2138/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/146172&quot;&gt;analysis&lt;/a&gt;). The round &lt;a href=&quot;https://codeforces.com/blog/entry/146176&quot;&gt;was unrated&lt;/a&gt;, which has delayed my inevitable downfall: I solved A+B(in the same wrong way as the problemsetters)+C1+C2 in 32 minutes, but could not solve anything else in the remaining 2.5 hours, even though I tried my hand at all remaining problems.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In &lt;a href=&quot;https://codeforces.com/contest/2138/problem/D&quot;&gt;D&lt;/a&gt;, I came up with a cubic solution first, then optimized it to quadratic, and then tried to optimize it to linear for a long time with no success, even though it always felt so close. Imagine my surprise when I reread the problem statement after the contest and learned that &lt;i&gt;n&lt;/i&gt;&amp;lt;=5*10&lt;sup&gt;3&lt;/sup&gt;, so I could have just submitted my quadratic solution :) I did submit the solution in upsolving and it passed after fixing two small bugs.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In &lt;a href=&quot;https://codeforces.com/contest/2138/problem/E1&quot;&gt;E&lt;/a&gt;, I was trying some randomized approaches, but they were not &lt;a href=&quot;https://codeforces.com/blog/entry/146172?#comment-1307436&quot;&gt;sophisticated enough&lt;/a&gt; to pass. Somehow it was hard to think constructively about determinants, although in retrospect choosing a tridiagonal matrix so that the determinant can be computed in one pass makes perfect sense.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In &lt;a href=&quot;https://codeforces.com/contest/2138/problem/F&quot;&gt;F&lt;/a&gt;, I only opened it in the last hour, and it turns out I almost managed to solve it in time&amp;nbsp;— the code was almost ready during the round, and my solution passed in upsolving after writing just a few more lines and some debugging. I have then uphacked my solution with the case &quot;141 9940 19882&quot;, but that won&#39;t have mattered during the round :) I am surprised nevertheless that such an extreme case (the case where there is no rounding in the computation of the number of allowed moves and that has the highest polar angle) was not in the system tests.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://cphof.org/profile/topcoder:ksun48&quot;&gt;Kevin&lt;/a&gt;, on the other hand, has managed to solve all of those problems (except the proper B :)) during the round. Well done and congratulations on the clear first place!&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5Z98d2G19LsATYFhHv3pDwY8btC0eTjBZSKioE2oCSLAEswcq7Wte2L5tJa-3NP52D4LrHHkd4AuqRqg5yWWIoLdto2q_FoDfN6OnBk9iYWDZi_wPxWhcohkDolmyVzLkrJw0KfSUdbEepgkJH7Z0IFcQqQn3ikANCgP_m9O9HTV666rUkl4CTta9MoQ/s1130/Screenshot%202025-09-14%20101904.png&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;268&quot; data-original-width=&quot;1130&quot; height=&quot;152&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5Z98d2G19LsATYFhHv3pDwY8btC0eTjBZSKioE2oCSLAEswcq7Wte2L5tJa-3NP52D4LrHHkd4AuqRqg5yWWIoLdto2q_FoDfN6OnBk9iYWDZi_wPxWhcohkDolmyVzLkrJw0KfSUdbEepgkJH7Z0IFcQqQn3ikANCgP_m9O9HTV666rUkl4CTta9MoQ/w640-h152/Screenshot%202025-09-14%20101904.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Wincent DragonByte 2025 Onsite Finals in Bratislava wrapped up the week (&lt;a href=&quot;https://www.wincentdragonbyte.com/archive#finals2025&quot;&gt;problems and analysis&lt;/a&gt;, &lt;a href=&quot;https://www.wincentdragonbyte.com/scoreboard/finals2025&quot;&gt;results&lt;/a&gt;, top 5 on the left). The top 2 places did not change from the Codeforces round :) Congratulations to all finalists and prize winners!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5SEKhVuok19n95eEMwGTN52M-O12owkWsnmVlNZ0aIFzM3wT10xfQ2B0gB_aopaRJh3qDEe63DJ6L0aTu2OS9tjsV-zh8CJci6ZA1Mx7tT8I3LnXHwPVRGvAoS5PtuhC9Csx8GyAFwhnIAbOgqwcu3GlMTbgHFM6t0M8ZJbNhZOSKuqy6iypD9s6qBJg/s2655/PXL_20250902_155900524.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;2094&quot; data-original-width=&quot;2655&quot; height=&quot;504&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5SEKhVuok19n95eEMwGTN52M-O12owkWsnmVlNZ0aIFzM3wT10xfQ2B0gB_aopaRJh3qDEe63DJ6L0aTu2OS9tjsV-zh8CJci6ZA1Mx7tT8I3LnXHwPVRGvAoS5PtuhC9Csx8GyAFwhnIAbOgqwcu3GlMTbgHFM6t0M8ZJbNhZOSKuqy6iypD9s6qBJg/w640-h504/PXL_20250902_155900524.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In my previous summary, I have mentioned &lt;a href=&quot;https://worldfinals.icpc.global/problems/2025/E-delivery.pdf&quot;&gt;an ICPC problem&lt;/a&gt;: you are given a graph with 2&lt;i&gt;n&lt;/i&gt; vertices and &lt;i&gt;m&lt;/i&gt; edges (&lt;i&gt;n&lt;/i&gt;&amp;lt;=2*10&lt;sup&gt;5&lt;/sup&gt;, &lt;i&gt;m&lt;/i&gt;&amp;lt;=4*10&lt;sup&gt;5&lt;/sup&gt;), the vertices are split into &lt;i&gt;n&lt;/i&gt;&amp;nbsp;pairs that we will call &lt;i&gt;blocks&lt;/i&gt;, let us call one vertex in a block&amp;nbsp;&lt;i&gt;red&lt;/i&gt; and another &lt;i&gt;blue&lt;/i&gt;. Every edge connects a red vertex with a blue vertex. The &lt;i&gt;m&lt;/i&gt; edges are added to the initially empty graph one by one. After each edge is added, you need to print the number of pairs of blocks (out of &lt;i&gt;n&lt;/i&gt;*(&lt;i&gt;n&lt;/i&gt;-1)/2 possibilities) that are connected (there exists a path connecting one of the four possiblities: between the red or the blue vertex in the first block and the red or the blue vertex in the second block).&lt;p&gt;&lt;/p&gt;&lt;p&gt;First, consider the following naive approach. Let us maintain the connected components in the graph, and for each component remember the set of blocks represented in it, which we can update via small-to-large merging. To compute the answer after adding every edge, we will just add up &lt;i&gt;b&lt;/i&gt;*(&lt;i&gt;b&lt;/i&gt;-1)/2 for each component, where &lt;i&gt;b&lt;/i&gt; is the number of different blocks represented in it.&lt;/p&gt;&lt;p&gt;Why is this approach naive? It will overcount in case two blocks are connected in two different connected components. But since each block has only two vertices, the only way this can really happen is that there are two components, each containing one vertex from each of the blocks. And moreover, we will overcount by exactly 1 for each pair of blocks with this property.&lt;/p&gt;&lt;p&gt;So let us also store the inverse mapping: for every block, we store the set of components it has representatives in. We can maintain those together with the above sets. Those sets will always have 1 or 2 elements. For those that have 2 elements, for each group&amp;nbsp;of&amp;nbsp;&lt;i&gt;c&lt;/i&gt;&amp;nbsp;equal such sets we need to just subtract &lt;i&gt;c&lt;/i&gt;*(&lt;i&gt;c&lt;/i&gt;-1)/2 from the answer. We can maintain the current answer and update it when those sets change.&lt;/p&gt;&lt;p&gt;This solution, by the way, is also by Kevin. Thanks for reading, and check back next week!&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/679791212938586059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/09/a-kevin-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/679791212938586059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/679791212938586059'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/09/a-kevin-week.html' title='A Kevin week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJDFxcC0BTVFfZLE0XEhyphenhyphenYYXKgGbaiFqcf7Stsi0QTLjadUVU29OTNU0krbPAynTwu73229uw9BWQa-Ee89lcfACTkWYFHQLRhCEHDABCVZ4Cmy545Fv9KA3e44fIFMBzAzOA56nAfSnP7H3LVBmljsCoutc1PQVvmEhMvnoeqB44gIqSMJkZ9A89WnXU/s72-w640-h159-c/Screenshot%202025-09-14%20102618.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-8186368699923056991</id><published>2025-09-05T16:54:00.000+02:00</published><updated>2025-09-05T16:54:32.914+02:00</updated><title type='text'>A polar week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjXi328VJ-R1fs2djs6b7xIkxjDDzfBgBul0mMUXf4Rk3aM7MmvS41UE4FB1yQvdu0XmQv41huCajDC5rQh7_w6klNttbX8rpfwrtOcjq3_zR83LDCBl6TQ-C7zzbboU3zj6Q4zYo8XdKiRfKMZMiUb81WIH2cwghyphenhyphenVprdX1MQ2oa31Q0IE8PTndZMZkE/s1790/Screenshot%202025-09-05%20154858.png&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;778&quot; data-original-width=&quot;1790&quot; height=&quot;278&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjXi328VJ-R1fs2djs6b7xIkxjDDzfBgBul0mMUXf4Rk3aM7MmvS41UE4FB1yQvdu0XmQv41huCajDC5rQh7_w6klNttbX8rpfwrtOcjq3_zR83LDCBl6TQ-C7zzbboU3zj6Q4zYo8XdKiRfKMZMiUb81WIH2cwghyphenhyphenVprdX1MQ2oa31Q0IE8PTndZMZkE/w640-h278/Screenshot%202025-09-05%20154858.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;ICPC World Finals 2025 #ICPCBaku was the main event of the week, and for many the main event of the year (&lt;a href=&quot;https://worldfinals.icpc.global/problems/2025/problemset.pdf&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://worldfinals.icpc.global/scoreboard/2025/&quot;&gt;results&lt;/a&gt;, top 12 on the left, &lt;a href=&quot;https://youtu.be/93DYRPNRrRA&quot;&gt;official stream&lt;/a&gt;, &lt;a href=&quot;https://youtu.be/85USZLnW3Po&quot;&gt;our stream&lt;/a&gt;). The St Petersburg State University team was always among the leaders, but they collected too many incorrect attempts and therefore the almost flawless University of Tokyo team was leading with a better penalty time on 10 problems just two minutes before the end. However, the&amp;nbsp;St Petersburg State University has managed to get the very difficult problem G accepted as well, and the university became the world champion for the &lt;a href=&quot;https://cphof.org/university/St.%20Petersburg%20State%20University&quot;&gt;5th time&lt;/a&gt;. Congratulations!&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For the University of Tokyo this means that they have earned &lt;a href=&quot;https://cphof.org/university/The%20University%20of%20Tokyo&quot;&gt;their 13th medal and 6th gold&lt;/a&gt;, but will unfortunately need to wait to lift the cup for a bit longer. I expect them&amp;nbsp;to do it soon, given the flourishing programming contest community in the university and in Tokyo in general. In any case, well done to them and to all medalists!&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRHvP8vmR3uDpu8l6K6lzk8T2yZjU0Kv6yt_21C0zxpl8eGay-jXz1LUTeCVYM-utgZY8PT4xUkB6N6x3UTpzHTWhdUhA-14XFsxl35mm2tlIPZHmbcGDRjILMiR428BudQtPhfJwwpNjlmPRgRVW7PjAzyWfzR9p-6duKZzAZVvG0Ez3bN1yVsWp9l9A/s4080/PXL_20250902_060608618.jpg&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;2271&quot; data-original-width=&quot;4080&quot; height=&quot;356&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRHvP8vmR3uDpu8l6K6lzk8T2yZjU0Kv6yt_21C0zxpl8eGay-jXz1LUTeCVYM-utgZY8PT4xUkB6N6x3UTpzHTWhdUhA-14XFsxl35mm2tlIPZHmbcGDRjILMiR428BudQtPhfJwwpNjlmPRgRVW7PjAzyWfzR9p-6duKZzAZVvG0Ez3bN1yVsWp9l9A/w640-h356/PXL_20250902_060608618.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;We have solved the mirror contest together with Kevin and Mateusz. It started reasonably well, but then initally Mateusz and then myself got stuck in &lt;a href=&quot;https://worldfinals.icpc.global/problems/2025/B-blackboardgame.pdf&quot;&gt;problem B&lt;/a&gt;, spending a lot of thinking time and computer time on it, but never getting it accepted.&lt;p&gt;&lt;/p&gt;&lt;p&gt;At the end of the contest, we tried to add some heuristics to speed up our matching code in B, but it was still too slow. The way that many teams used to work around it is to have a separate solution for &quot;large enough&quot; values of &lt;i&gt;n&lt;/i&gt;, either a direct mathematical one or one obtained by looking for patterns in the outputs in the matching solution for small values of &lt;i&gt;n&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;However (it is always somehow easier to think after the contest ends...) today I have tried another approach that seems obvious in retrospect: since we just need to find an even number that is not covered by &lt;i&gt;some&lt;/i&gt; matching, and in the normal bipartite matching algorithm (usually called Kuhn&#39;s in the programming contest circles) as soon as we&#39;re unable to find an augmenting path from a certain vertex of the first part, we know that it will not be covered by the final matching, we can stop the matching algorithm as soon as a search starting from an even number is unsuccessful. On my laptop, it makes the code run in 0.6s for &lt;i&gt;n&lt;/i&gt;=10&lt;sup&gt;7&lt;/sup&gt;. I could not find any working upsolving to test this properly, please share a link if you know one!&lt;/p&gt;&lt;p&gt;Another problem that I found very nice was &lt;a href=&quot;https://worldfinals.icpc.global/problems/2025/E-delivery.pdf&quot;&gt;problem E&lt;/a&gt;: you are given a graph with 2&lt;i&gt;n&lt;/i&gt; vertices and &lt;i&gt;m&lt;/i&gt; edges (&lt;i&gt;n&lt;/i&gt;&amp;lt;=2*10&lt;sup&gt;5&lt;/sup&gt;, &lt;i&gt;m&lt;/i&gt;&amp;lt;=4*10&lt;sup&gt;5&lt;/sup&gt;), the vertices are split into &lt;i&gt;n&lt;/i&gt;&amp;nbsp;pairs that we will call &lt;i&gt;blocks&lt;/i&gt;, let us call one vertex in a block&amp;nbsp;&lt;i&gt;red&lt;/i&gt; and another &lt;i&gt;blue&lt;/i&gt;. Every edge connects a red vertex with a blue vertex. The &lt;i&gt;m&lt;/i&gt; edges are added to the initially empty graph one by one. After each edge is added, you need to print the number of pairs of blocks (out of &lt;i&gt;n&lt;/i&gt;*(&lt;i&gt;n&lt;/i&gt;-1)/2 possibilities) that are connected (there exists a path connecting one of the four possiblities: between the red or the blue vertex in the first block and the red or the blue vertex in the second block). If not for the complication with the blocks, it would be a simple union-find application, but can you see how to deal with the blocks?&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back next week!&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/8186368699923056991/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/09/a-polar-week.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/8186368699923056991'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/8186368699923056991'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/09/a-polar-week.html' title='A polar week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjXi328VJ-R1fs2djs6b7xIkxjDDzfBgBul0mMUXf4Rk3aM7MmvS41UE4FB1yQvdu0XmQv41huCajDC5rQh7_w6klNttbX8rpfwrtOcjq3_zR83LDCBl6TQ-C7zzbboU3zj6Q4zYo8XdKiRfKMZMiUb81WIH2cwghyphenhyphenVprdX1MQ2oa31Q0IE8PTndZMZkE/s72-w640-h278-c/Screenshot%202025-09-05%20154858.png" height="72" width="72"/><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-6297634935494687602</id><published>2025-09-03T11:58:00.006+02:00</published><updated>2025-09-04T10:20:07.559+02:00</updated><title type='text'>A chess day</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8EYxtMAAxbxJSAVJY9r4mKF7k0S1BZVSmC8aVwE78FjBbHHG_W7r2NN8UhSz9GDnMQlbQmFeMZtonmsmM22_iDEdOHgCqCMkuJkZw8FO1JqyTS3Y3KRn9B6CZLRm8YOTRqqRBsppPG9TrDsKRZ11osAdi72dxGNvL7IJTwV0wnaCrP_8Ne6exAYzIcrU/s4080/PXL_20250902_081410004.MP.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8EYxtMAAxbxJSAVJY9r4mKF7k0S1BZVSmC8aVwE78FjBbHHG_W7r2NN8UhSz9GDnMQlbQmFeMZtonmsmM22_iDEdOHgCqCMkuJkZw8FO1JqyTS3Y3KRn9B6CZLRm8YOTRqqRBsppPG9TrDsKRZ11osAdi72dxGNvL7IJTwV0wnaCrP_8Ne6exAYzIcrU/w640-h482/PXL_20250902_081410004.MP.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Yesterday was the day of the &lt;a href=&quot;https://youtu.be/h4cg2DT7MIc&quot;&gt;Dress Rehearsal&lt;/a&gt; and the &lt;a href=&quot;https://youtu.be/7Am8EnmQiUE&quot;&gt;Tech Trek&lt;/a&gt; at #ICPCBaku. I am planning to solve the mirror contest on Thursday together with &lt;a href=&quot;https://cphof.org/profile/topcoder:ksun48&quot;&gt;Kevin&lt;/a&gt; and &lt;a href=&quot;https://cphof.org/profile/topcoder:Stonefeang&quot;&gt;Mateusz&lt;/a&gt;, so we used the Dress Rehearsal time to practice our solving and streaming setup as well (photo on the left). Unfortunately we could not practice the submissions since it seems that &lt;a href=&quot;https://wf25open.kattis.com/contests/wf25open&quot;&gt;the mirror&lt;/a&gt; was not available for the Dress Rehearsal, but the rest seems in order. Tune in tomorrow (Thursday) at &lt;a href=&quot;https://www.timeanddate.com/worldclock/fixedtime.html?msg=ICPC+World+Finals+2025&amp;amp;iso=20250904T11&amp;amp;p1=369&amp;amp;ah=5&quot;&gt;11:00 Baku time&lt;/a&gt; to &lt;a href=&quot;https://twitch.tv/petrmitrichev&quot;&gt;my Twitch&lt;/a&gt; to watch us compete! You will also be able to look at &lt;a href=&quot;https://live.icpc.global&quot;&gt;the official broadcast&lt;/a&gt; of the real contest, its &lt;a href=&quot;https://worldfinals.icpc.global/scoreboard/2025/&quot;&gt;scoreboard&lt;/a&gt; and&amp;nbsp;&lt;a href=&quot;https://worldfinals.icpc.global/problems/2025/&quot;&gt;problems&lt;/a&gt;&amp;nbsp;(you can find more links &lt;a href=&quot;https://codeforces.com/blog/entry/145994&quot;&gt;here&lt;/a&gt;), and of course please support the #ETH team!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWN9RrO3FtU51ocyy4B9yiYkEpFrCY_Zd7w_ddOP7McbZMuoloOvy9ajX1GlXc73oD-ve5kZ2HDe9-VdRzMrfBEG_3sizJUfv2atRSy8tS1-3as7uvuWA_9msr-F5s1OTcb4TnHEbd5C4ycIxp4LHpUJyCwFKafWVZwR0R67l0zYzwXyYaY0fsZdrDLJU/s4080/PXL_20250902_190719031.jpg&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;2580&quot; data-original-width=&quot;4080&quot; height=&quot;404&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWN9RrO3FtU51ocyy4B9yiYkEpFrCY_Zd7w_ddOP7McbZMuoloOvy9ajX1GlXc73oD-ve5kZ2HDe9-VdRzMrfBEG_3sizJUfv2atRSy8tS1-3as7uvuWA_9msr-F5s1OTcb4TnHEbd5C4ycIxp4LHpUJyCwFKafWVZwR0R67l0zYzwXyYaY0fsZdrDLJU/w640-h404/PXL_20250902_190719031.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Today is the &lt;a href=&quot;https://youtu.be/gMUxBz4RR_U&quot;&gt;ICPC Challenge&lt;/a&gt; day, with the results due to be &lt;a href=&quot;https://youtu.be/ZNrCbLbcdB8&quot;&gt;announced&lt;/a&gt; in a couple of hours. In the evening &lt;a href=&quot;https://worldfinals.icpc.global/alumni.html&quot;&gt;the Alumni-hosted events&lt;/a&gt;&amp;nbsp;will continue, and I have decided to use my slot for an online chess tournament for the World Finals onsite attendees. Here is how I propose to run it:&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;We will run a 5-round &lt;a href=&quot;https://lichess.org/swiss/cdz3n9LB&quot;&gt;Swiss tournament on lichess&lt;/a&gt;&amp;nbsp;with 3+0 time control (3 minutes for each side per game, no increment). This yields a ~30-minute duration but if games finish earlier hopefully it will be a bit faster and everybody will be in time for the push-ups :)&lt;/li&gt;&lt;li&gt;To join the tournament, you need a lichess account and a phone or a laptop to play. If you do not have a lichess account and want to participate, please create it in advance!&lt;/li&gt;&lt;li&gt;To join the tournament, you also need to join &lt;a href=&quot;https://lichess.org/team/icpc-world-finals-2025-baku&quot;&gt;this team&lt;/a&gt; on lichess first. I will need to approve everybody who wants to join the team so that it keeps being an onsite event, so you will need to find me in person for that.&lt;/li&gt;&lt;li&gt;The easiest way to find me in person will be to come to the Chill Zone in the&amp;nbsp;Marriott Blvd today at 17:30 (or a bit earlier).&lt;/li&gt;&lt;li&gt;The tournament will start at 17:35, so don&#39;t be late! If you are late, you should be able to join the tournament late during the first two rounds as well, but then you will miss some games :)&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;If you have any questions, please ask in comments here or on Codeforces!&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/6297634935494687602/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/09/a-chess-day.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/6297634935494687602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/6297634935494687602'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/09/a-chess-day.html' title='A chess day'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8EYxtMAAxbxJSAVJY9r4mKF7k0S1BZVSmC8aVwE78FjBbHHG_W7r2NN8UhSz9GDnMQlbQmFeMZtonmsmM22_iDEdOHgCqCMkuJkZw8FO1JqyTS3Y3KRn9B6CZLRm8YOTRqqRBsppPG9TrDsKRZ11osAdi72dxGNvL7IJTwV0wnaCrP_8Ne6exAYzIcrU/s72-w640-h482-c/PXL_20250902_081410004.MP.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-2994175374653857362</id><published>2025-09-01T17:21:00.000+02:00</published><updated>2025-09-01T17:21:00.991+02:00</updated><title type='text'>An alumni day</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjyChH-eRFNtgKw9Cbhf_IWpdmLa2QU6puQAjXzo84JL1dWfHG_tkL5sNRaYTmwuBc5R8ItREvA2qJWimV55S9VD_THHak5Wo9zSysOMn9pH7_Fy9bs7XBADx75ar_1GsUYYGlJeiNzjl3QZPiXGAZpEwG3tMbFLCGfWKj0UH2DBHw6UuAD2EgC6LXGco/s4080/PXL_20250901_133609370.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjyChH-eRFNtgKw9Cbhf_IWpdmLa2QU6puQAjXzo84JL1dWfHG_tkL5sNRaYTmwuBc5R8ItREvA2qJWimV55S9VD_THHak5Wo9zSysOMn9pH7_Fy9bs7XBADx75ar_1GsUYYGlJeiNzjl3QZPiXGAZpEwG3tMbFLCGfWKj0UH2DBHw6UuAD2EgC6LXGco/w640-h482/PXL_20250901_133609370.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The &lt;a href=&quot;https://youtu.be/qFAJGXxZwiQ&quot;&gt;Alumni Talk&lt;/a&gt; and the &lt;a href=&quot;https://youtu.be/vXvoyBaeGFw&quot;&gt;Opening Ceremony&lt;/a&gt; were the main events of the ICPC World Finals 2025 today. Among other things, they demonstrated two of the best careers (according to my own perception, of course :)) that the ICPC crowd can choose: the Alumni Talk was about fundamental computer science research, in this case of the core graph shortest path algorithms, while the Opening Ceremony introduced two new sponsors, Google DeepMind and OpenAI, which represent just as cutting-edge but more practical ML/AI research. On a more meta note, it is fascinating how from talking with different ICPC participants and alumni, there are those that consider it an important career step to one of the above fields, there are also those who really want to win it or get a medal, but there are also those who are here to have fun and mingle with like-minded people, and the event works great for all of them. Well done to the organizers!&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB3wCp0iM-Bf_A-kRdZwiUioFLbY9nesES9XdYCKpkM_SIdPmLCh0bshbjDRjjPCrvuGvkct_nUKVOG2ld0OaUdijMxmRDCS4s70933NlUV686KsBk_Mz2JCgqnrYhezPfaN5RJm4PNqkp3c1lG-_TvgPyH8VG0Q8NhX7ZLgRacaMClAQ1bhNQ-7IolLE/s3290/PXL_20250628_145303860-EDIT.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;2180&quot; data-original-width=&quot;3290&quot; height=&quot;424&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB3wCp0iM-Bf_A-kRdZwiUioFLbY9nesES9XdYCKpkM_SIdPmLCh0bshbjDRjjPCrvuGvkct_nUKVOG2ld0OaUdijMxmRDCS4s70933NlUV686KsBk_Mz2JCgqnrYhezPfaN5RJm4PNqkp3c1lG-_TvgPyH8VG0Q8NhX7ZLgRacaMClAQ1bhNQ-7IolLE/w640-h424/PXL_20250628_145303860-EDIT.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Another highlight of this year is &lt;a href=&quot;https://worldfinals.icpc.global/alumni.html&quot;&gt;a series of alumni events&lt;/a&gt; which are not on &lt;a href=&quot;https://docs.icpc.global/wf-schedule/&quot;&gt;the main schedule&lt;/a&gt;, but for me personally look more interesting than many of the main events. If you&#39;re onsite in Baku, come chat with us, in particular I will be hosting on Wednesday at 17:30! I am also looking for a topic for my session, even though &quot;Meet and Greet&quot; also works. One topic that flows naturally from this blog is something like &quot;blogging in the age of TikTok and Discord&quot;, but I&#39;m not sure if it is the most interesting one :)&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsL8sy7PcnXv8b62NNSxJSNuj_LKv8ukQX9510c65LMEDB6Hu2AnAXbrFj9YDxN_QjpbAAm4W7z2qiCnnLU7JlJlWuA8NSJ5-s0U91dt_rHDFq2aFHZAUXUZ4kv3-G_RR8VQGjCpXn-U5YHhINJrlgu7NytUu6CaG3p3pXYNAd_-16ytLofJWhunDDtE0/s2464/26711313446_1994f1a330_o.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1648&quot; data-original-width=&quot;2464&quot; height=&quot;428&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsL8sy7PcnXv8b62NNSxJSNuj_LKv8ukQX9510c65LMEDB6Hu2AnAXbrFj9YDxN_QjpbAAm4W7z2qiCnnLU7JlJlWuA8NSJ5-s0U91dt_rHDFq2aFHZAUXUZ4kv3-G_RR8VQGjCpXn-U5YHhINJrlgu7NytUu6CaG3p3pXYNAd_-16ytLofJWhunDDtE0/w640-h428/26711313446_1994f1a330_o.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;The ICPC Quest today asked us to go back to the old photos in the &lt;a href=&quot;https://news.icpc.global/gallery/?query=moscow+state+university&amp;amp;photo=26711313446&quot;&gt;ICPC photo gallery&lt;/a&gt;. My photos in the ICPC photo gallery do start with my first participation in 2003 in Beverly Hills, and you can see the one I like the most from that year on the left.&lt;p&gt;&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back tomorrow for more #ICPCBaku updates!&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/2994175374653857362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/09/an-alumni-day.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/2994175374653857362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/2994175374653857362'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/09/an-alumni-day.html' title='An alumni day'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjyChH-eRFNtgKw9Cbhf_IWpdmLa2QU6puQAjXzo84JL1dWfHG_tkL5sNRaYTmwuBc5R8ItREvA2qJWimV55S9VD_THHak5Wo9zSysOMn9pH7_Fy9bs7XBADx75ar_1GsUYYGlJeiNzjl3QZPiXGAZpEwG3tMbFLCGfWKj0UH2DBHw6UuAD2EgC6LXGco/s72-w640-h482-c/PXL_20250901_133609370.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-1880935971568239370</id><published>2025-08-31T15:32:00.000+02:00</published><updated>2025-08-31T15:32:15.340+02:00</updated><title type='text'>A universal week</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDYUGCwr-ibKXTpFOvDwq8oseu7908RL7BQ6Xx1uJlMJMYY6629HN5QAJsCd65llU9SvhhioYtyCHwy7hnGP1FquFdEqT4W5L8pz8BMflvBCxe90H29yd9ww-W284bgMtnGSvfs_eK45N6p644pEpbLK4WK_HIovXQxDkX4F8zBk4im5IR-kxA9uIpoTU/s1112/Screenshot%202025-08-31%20143714.png&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;240&quot; data-original-width=&quot;1112&quot; height=&quot;138&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDYUGCwr-ibKXTpFOvDwq8oseu7908RL7BQ6Xx1uJlMJMYY6629HN5QAJsCd65llU9SvhhioYtyCHwy7hnGP1FquFdEqT4W5L8pz8BMflvBCxe90H29yd9ww-W284bgMtnGSvfs_eK45N6p644pEpbLK4WK_HIovXQxDkX4F8zBk4im5IR-kxA9uIpoTU/w640-h138/Screenshot%202025-08-31%20143714.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Last week, the main round was the 3rd Universal Cup Semifinals (&lt;a href=&quot;https://contest.ucup.ac/contest/2506&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://contest.ucup.ac/results/QOJ2506&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://qoj.ac/blog/qingyu/blogs/1362&quot;&gt;analysis&lt;/a&gt;, &lt;a href=&quot;https://youtu.be/nsG8_OqByDw&quot;&gt;contest stream&lt;/a&gt;, &lt;a href=&quot;https://youtu.be/zyEWyW1M5KE&quot;&gt;closing ceremony stream&lt;/a&gt;). For those not familiar with the Universal Cup, &lt;a href=&quot;https://codeforces.com/blog/entry/145627&quot;&gt;this announcement&lt;/a&gt; has some links for more information, but in short, it is a competition with many online stages throughout the year (40 in the 3rd season, but the organizers plan to reduce the number significantly for the 4th season to reduce the pressure on the teams trying to qualify for the Finals), each stage being a 5-hour contest with ICPC rules, usually with the problems from a regional or another previous non-public contest. The results over all stages are then aggregated into &lt;a href=&quot;https://ucup.ac/rating/&quot;&gt;a rating&lt;/a&gt; (the formula will also be changed for the 4th season), and the top teams from this rating are invited into the &lt;a href=&quot;https://cphof.org/standings/ucup/2025&quot;&gt;Finals&lt;/a&gt;, which took place onsite in China for the 2nd season, and it&#39;s not yet clear if it will be onsite or online for the 3rd season that just finished. Recognizing the fact that some strong teams do not have the time to participate regularly, the organizers also host a Semifinals competition online, where every team can enter, and a few more spots for the Finals are won.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Team USA1 has continued their domination of the Universal Cup&amp;nbsp;— congratulations! Since they and a few other teams at the top have already qualified for the Finals by the virtue of their regular season result (also 1st), the first team who advanced to the Finals from this round was team&amp;nbsp;arvin and errogame, and maybe even more importantly, the last team who advanced to the Finals from this round (future cancellations notwithstanding) was team&amp;nbsp;Dvoe protiv vetra. Well done to all finalists!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I and my team were also looking forward to participating in this round, but unfortunately a last-minute conflict interfered with my plans. Now I think we need to do at least one and hopefully more stages of the 4th season instead!&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCl-MBUhOGBGdFizYTQcUhqy8f9ntU0ZdxxN0uHX8_eMGw_S6ay7GuQq0NBRFCxpWph0OMynD8kMpPPMfVCD9F8a0Q7xDPYIRp0JoCjTQDilZAA0SxommFcnh59aLc0uGcQEt4t1uLeiK3NIHVdP-qJH5-nkc1xvX7C8PEC9AQP7utqi4utklfwYy72s0/s1103/Screenshot%202025-08-31%20144117.png&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;276&quot; data-original-width=&quot;1103&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCl-MBUhOGBGdFizYTQcUhqy8f9ntU0ZdxxN0uHX8_eMGw_S6ay7GuQq0NBRFCxpWph0OMynD8kMpPPMfVCD9F8a0Q7xDPYIRp0JoCjTQDilZAA0SxommFcnh59aLc0uGcQEt4t1uLeiK3NIHVdP-qJH5-nkc1xvX7C8PEC9AQP7utqi4utklfwYy72s0/w640-h160/Screenshot%202025-08-31%20144117.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;This week Codeforces Round 1046 led the way (&lt;a href=&quot;https://codeforces.com/contest/2135&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2135/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, &lt;a href=&quot;https://codeforces.com/blog/entry/145796&quot;&gt;analysis&lt;/a&gt;). Each problem was solved by at least 4 contestants, but only jiangly managed to put all of them together, with just 3 minutes remaining in the round. Congratulations on the convincing victory!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn7A99JCEQlKrq4vNNSJyIz3W9dgSY789mIYWC2bDag9jI0zgGDZcpq2s2l2T-YQIP_Kt8KHUQ0-QbGTgOLZeXEdwH3wNp9eUFMwVLU7bta1nqx4Axv1exmQ66dgIgX94y0q6bvZiMAq9quDIDVzsYLCKOE2xV8ltIwnHb5cy8hIz0w6Y0ZnsAsKHOhhA/s4080/PXL_20250608_162132913.MP.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn7A99JCEQlKrq4vNNSJyIz3W9dgSY789mIYWC2bDag9jI0zgGDZcpq2s2l2T-YQIP_Kt8KHUQ0-QbGTgOLZeXEdwH3wNp9eUFMwVLU7bta1nqx4Axv1exmQ66dgIgX94y0q6bvZiMAq9quDIDVzsYLCKOE2xV8ltIwnHb5cy8hIz0w6Y0ZnsAsKHOhhA/w640-h482/PXL_20250608_162132913.MP.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;And next week, it&#39;s all about&amp;nbsp;&lt;a href=&quot;https://worldfinals.icpc.global/&quot;&gt;#ICPCBaku&lt;/a&gt;. I will be there as well and try to share some tidbits in this blog, so check back soon!&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/1880935971568239370/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/08/a-universal-week.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/1880935971568239370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/1880935971568239370'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/08/a-universal-week.html' title='A universal week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDYUGCwr-ibKXTpFOvDwq8oseu7908RL7BQ6Xx1uJlMJMYY6629HN5QAJsCd65llU9SvhhioYtyCHwy7hnGP1FquFdEqT4W5L8pz8BMflvBCxe90H29yd9ww-W284bgMtnGSvfs_eK45N6p644pEpbLK4WK_HIovXQxDkX4F8zBk4im5IR-kxA9uIpoTU/s72-w640-h138-c/Screenshot%202025-08-31%20143714.png" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-3617671946025842765</id><published>2025-08-23T13:43:00.000+02:00</published><updated>2025-08-23T13:43:24.629+02:00</updated><title type='text'>A byte week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu4RfLbzF60F_XWmGbtQ_0Wfa5MLeiyLVy6Pg5VPj4HrnqfWDG6x95sEEUt-P3N-1mVKWEN1fu601nGd7rgekksK8OujoZhdl4W5psb8ZOrG0NXp14u4jsv6fcGxRMF8THLe7B-0SVGs9zLzy6p6Lf38chErR7FrfYLepaPfxs4a1wNtKGzoZ38DRjnuk/s4080/PXL_20250511_133228032.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3072&quot; data-original-width=&quot;4080&quot; height=&quot;482&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu4RfLbzF60F_XWmGbtQ_0Wfa5MLeiyLVy6Pg5VPj4HrnqfWDG6x95sEEUt-P3N-1mVKWEN1fu601nGd7rgekksK8OujoZhdl4W5psb8ZOrG0NXp14u4jsv6fcGxRMF8THLe7B-0SVGs9zLzy6p6Lf38chErR7FrfYLepaPfxs4a1wNtKGzoZ38DRjnuk/w640-h482/PXL_20250511_133228032.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;There was no contest that I wanted to mention last week. Since I am getting such empty weeks quite often now, I&#39;ve decided to check unfiltered &lt;a href=&quot;https://clist.by&quot;&gt;clist&lt;/a&gt;&amp;nbsp;in case I have missed something. And indeed, there seems to be an onsite round of a &lt;a href=&quot;https://codeforces.com/blog/entry/143365&quot;&gt;competition&lt;/a&gt; called Wincent DragonByte coming up in September which I only discovered today, and therefore missed my chance to qualify for the onsite finals in Bratislava :) It is a pity but in the grand scheme of things there are of course so many contests I already took part in and hopefully even more that I will take part in.&lt;p&gt;&lt;/p&gt;&lt;p&gt;Nevertheless, this raises a logical question: what would be a good strategy to avoid missing such nice competitions? Reading all Codeforces posts does not seem to work, and neither does checking clist regularly enough. Is there a way to get notified when new contest websites are added to clist maybe (for example, maybe one can achieve that by excluding less relevant resources via &quot;hide&quot; rules in the filters, as opposed to choosing the relevant resources as &quot;show&quot;, which I am doing now)? Or should I create an AI bot that checks unfiltered clist or unfiltered Codeforces and decides if I should be notified? What is your strategy? And of course, what other cool contests am I already missing? :)&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back for this week&#39;s summary!&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/3617671946025842765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/08/a-byte-week.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/3617671946025842765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/3617671946025842765'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/08/a-byte-week.html' title='A byte week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu4RfLbzF60F_XWmGbtQ_0Wfa5MLeiyLVy6Pg5VPj4HrnqfWDG6x95sEEUt-P3N-1mVKWEN1fu601nGd7rgekksK8OujoZhdl4W5psb8ZOrG0NXp14u4jsv6fcGxRMF8THLe7B-0SVGs9zLzy6p6Lf38chErR7FrfYLepaPfxs4a1wNtKGzoZ38DRjnuk/s72-w640-h482-c/PXL_20250511_133228032.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1953325079793449971.post-8529981975069797503</id><published>2025-08-09T12:28:00.002+02:00</published><updated>2025-08-09T12:29:50.624+02:00</updated><title type='text'>A thesis week</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKvHh5G0pWRv2V-hehnhWNSuZg3fUctALfNsUjXayNS9AvGoAPY4BCWa0DK1c0TJl_gW9Q-0nQk-42SbaX1W_PoVZMCiqfV6ERfJn0USGHJBKoXiUouewTOWGg3JwACoFET4GdHbo691DrJvBm_5GBMcuB9F3O-n4AYgYg6Zmh-agu2qWySDOb1Yq-vx0/s1102/Screenshot%202025-08-09%20113004.png&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;277&quot; data-original-width=&quot;1102&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKvHh5G0pWRv2V-hehnhWNSuZg3fUctALfNsUjXayNS9AvGoAPY4BCWa0DK1c0TJl_gW9Q-0nQk-42SbaX1W_PoVZMCiqfV6ERfJn0USGHJBKoXiUouewTOWGg3JwACoFET4GdHbo691DrJvBm_5GBMcuB9F3O-n4AYgYg6Zmh-agu2qWySDOb1Yq-vx0/w640-h160/Screenshot%202025-08-09%20113004.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Atto Round 1, also known as Codeforces Round 1041, was the main event of the week (&lt;a href=&quot;https://codeforces.com/contest/2127&quot;&gt;problems&lt;/a&gt;, &lt;a href=&quot;https://codeforces.com/contest/2127/standings&quot;&gt;results&lt;/a&gt;, top 5 on the left, analysis). With &lt;a href=&quot;https://codeforces.com/contest/2127/problem/H&quot;&gt;problem H&lt;/a&gt; turning out way easier than the problemsetters have expected, the top places were decided on &lt;a href=&quot;https://codeforces.com/contest/2127/problem/G1&quot;&gt;problem G&lt;/a&gt; concerning permutations and their compositions, which for me was just very hard to load into RAM to even think about it :) At the end of the contest I came up with a randomized solution that takes 15 random permutations and asks all their cyclic shifts. It actually passed G1 in upsolving, but during the round I did not manage to find all off-by-one and permutation-instead-of-inverse bugs. But even in upsolving it seemed hopeless for G2 where we only get to take 10 such permutations.&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiMiPUf3RhbWljs4OVdxQ7w8duKmyVrRJ-XM0ckCDshwttXqUf0IsPnLeH2_3SEeLOguJ8hJx8WjXa4lZJ12y9_-z4_L7SlGN4c2iiIarDFx7DoZ6BGzp5jn7Cv-L3v8cju89SNdETiFThn_eHZoqWS3tRELTTenvdvWnY69tiKKLKtklKDaORRRjMD_JQ&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;74&quot; data-original-width=&quot;225&quot; height=&quot;66&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiMiPUf3RhbWljs4OVdxQ7w8duKmyVrRJ-XM0ckCDshwttXqUf0IsPnLeH2_3SEeLOguJ8hJx8WjXa4lZJ12y9_-z4_L7SlGN4c2iiIarDFx7DoZ6BGzp5jn7Cv-L3v8cju89SNdETiFThn_eHZoqWS3tRELTTenvdvWnY69tiKKLKtklKDaORRRjMD_JQ=w200-h66&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;It turns out that Kevin has won the round with exactly the same solution. To pass G2, he tried 1000 different random sets of 10 permutations before starting to ask questions, and chose the set that gives the least collisions. This turned out to be borderline good enough, and 4 submissions that differed only in the random seed (diff on the right) sealed the deal. Well done Kevin, and also well done Jiangly on solving G2 in the &quot;on paper&quot; way :)&lt;p&gt;&lt;/p&gt;&lt;p&gt;I got my share of successful randomized solving in problem H, where after being stuck for a while I decided to submit a solution that took edges that can definitely be taken, and when there is no such edge, took a more or less random edge and continued, and then repeated this process until the time runs out. This should be roughly the same as backtracking but even simpler to implement, and I expected that with &lt;i&gt;n&lt;/i&gt;=30 it has a high change of passing, and indeed it did from the first attempt in which I fixed all bugs.&lt;/p&gt;&lt;p&gt;It is curious that neither problemsetters nor myself were able to see:&lt;/p&gt;&lt;p&gt;1) the relatively standard dynamic programming solution for the problem that takes advantage of the fact that from every subtree of the DFS tree we have at most 5 backward edges, and therefore can just add the state of all those edges to the dynamic programming state.&lt;/p&gt;&lt;p&gt;2) the non-bipartite matching solution that does not even rely on the additional &quot;at most 5&quot; property from the problem statement: the problem statement essentially asks for maximum matching, but where each vertex can be used twice instead of once, so we can just duplicate the vertices and be done.&lt;/p&gt;&lt;p&gt;Point 2 is even more bizarre in my case, since my masters thesis 18 years ago was on a more general version of exactly this problem, 2-path-packings. The thesis was in Russian and I don&#39;t think it is published anywhere, but it is roughly equivalent to chapter 3 &quot;O(mn)-time algorithm&quot; in &lt;a href=&quot;http://dagstuhl.sunsite.rwth-aachen.de/volltexte/2017/8275/pdf/LIPIcs-ISAAC-2017-8.pdf&quot;&gt;this paper&lt;/a&gt;. So the matching interpretation should really have been obvious to me, even after 18 years :)&lt;/p&gt;&lt;p&gt;Thanks for reading, and check back next week!&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.mitrichev.ch/feeds/8529981975069797503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.mitrichev.ch/2025/08/a-thesis-week.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/8529981975069797503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1953325079793449971/posts/default/8529981975069797503'/><link rel='alternate' type='text/html' href='http://blog.mitrichev.ch/2025/08/a-thesis-week.html' title='A thesis week'/><author><name>Petr Mitrichev</name><uri>http://www.blogger.com/profile/00138130656174416711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKvHh5G0pWRv2V-hehnhWNSuZg3fUctALfNsUjXayNS9AvGoAPY4BCWa0DK1c0TJl_gW9Q-0nQk-42SbaX1W_PoVZMCiqfV6ERfJn0USGHJBKoXiUouewTOWGg3JwACoFET4GdHbo691DrJvBm_5GBMcuB9F3O-n4AYgYg6Zmh-agu2qWySDOb1Yq-vx0/s72-w640-h160-c/Screenshot%202025-08-09%20113004.png" height="72" width="72"/><thr:total>2</thr:total></entry></feed>