Walking_Dead, known as a spy from the US in our computer room, said that he couldn't get the meaning of my solutions all the time. That's why I'm writing this solution set in English instead of Chinese.

「AGC 013C」Ants on a Circle

  Tags:「C.性质/结论」「C.思维」


  It's an interesting problem after all.

  On the one hand, because there can't be two ants swapping their relative position at any time, the final identities of ants reading from \(x=0\) to \(x=L-1\) must be a rotation of \([1,2,\dots,n]\). On the other hand, a well-known transformation of this kind of problems is to let two ants cross each other when they meet, without turning their way. Therefore, it's easy to work out the final positions for all ants - \(\{(x_i+T)\bmod L\}_{i=1}^n\). Combining two properties above, our rest task is to find the ant \(1\)'s final position in \(\{(x_i+T)\bmod L\}_{i=1}^n\).

  Difficulty comes from "circle", so let's expand it out. for an ant \(i\), let it appear at positions \(i+kn\) for all integer \(k\). By simply counting how many ants cross the position \(-0.5\), we can find the final position for the ant whose initial position is \(1\). If that position is \(x=r+kn\), it suggests the final position of ant \(1\) is \(r\). Knowing this, we can find the answer with mentioned properties quickly.

  The complexity for this algorithm is \(\mathcal O(n\log n)\) due to sorting \(\{(x_i+T)\bmod L\}_{i=1}^n\).

「AGC 013D」Piling Up ^

  Tags:「A.DP-计数 DP」「B.模型转化」


  Confusing ... Does anyone think this problem is easier than the above one?

  Initially, we separate the original operation "take-put-take" into two operations "take-put" and "take". Then, locating a state "after \(i\) operations, \(r\) red balls and \(n-i+[2\nmid i]-r\) blue balls remain in the box" at \((i,r)\) on a grid, one can see that \(2m\) operations are drawn as a broken line. And, a color sequence corresponds to a broken line that touched \(y=0\) at least once. Therefore, we can DP the number of such broken lines to solve this problem in \(\mathcal O(nm)\) time.

「AGC 013E」Placing Squares ^

  Solution.

「AGC 013F」Two Faced Cards *

  Tags:「B.贪心」「C.思维」


  Let \(n\gets n+1\). Since all we know the Hall's theorem, if given two array \(\{a_n\}\) and \(\{c_n\}\), we can check if there's a legal match as follows: maintain a sequence \([s_1,s_2,\cdots,s_n]=[0,0,\cdots,0]\) initially. Then for \(i\in[1,n]\) and \(j\in[a_i,n]\), let \(s_j\gets s_j-1\), and for \(i\in[1,n]\) and \(j\in[c_i,n]\), let \(s_j\gets s_j+1\). A match exists iff all \(s_i\ge0\) eventually.

  Go back to the original problem. Greedily, we won't flip any card at the beginning, so there may be some \(s_i<0\) after performing the operation above. Remember that a query can offer an extra card \(x\), which means \(s\) is legal iff \(s_i\ge0\) for \(i<x\) and \(s_i\ge-1\) for \(i\ge x\). Regardless \(x\), we have another choice to change \(s\) - flipping a card \((a,b)\), which will increase \(s_i\) by \(1\) for \(i\in[b,a)\). Only \(n\) possible \(x\) existing, let's try to find the minimal flipping time for all \(x\in[1,n]\).

  Our first task is to flip some cards to get all \(s_i\ge-1\). Maybe hearing an oracle, we suddenly come up with a greedy algorithm: scan \(s\) from \(i=n\) to \(i=1\), and if an \(s_i<-1\) is found, we continually choose a interval \([b,a)\) containing \(i\) with minimal \(b\), and flip card \((a,b)\) until \(s_i\ge-1\). We can prove the correctness through a simple swapping-discussion. In my opinion, the biggest obstacle to this solution is to choose a right scanning direction on \(s\). Counterintuitive as it is, we may reach it after having tried scanning from \(i=1\) to \(i=n\) and failed to prove a greedy algorithm. (Or, just click "Editorial" like me.)

  The rest part of the task is much easier - scanning \(s\) again from \(i=1\) to \(i=n\) and making \(s_i\ge0\) with intervals \([b,a)\) containing \(i\) with maximal \(a\). When \(s_i\ge0\) for \(i<x_0\), update the answer for \(x=x_0\) by current swapping time.

  Using heap to maintain data required, we can do things above in \(\mathcal O(n\log n)\) time.

「AGC 014C」Closed Rooms

  Tag:「水题无 tag」


  超级可爱的一道题不是吗, 对于新手的确很 educational.

  不难注意到, 当我们第一次使用解锁操作后, 最优情况下, 我们不可能再被任何障碍阻挡. 也就是说, 第一次使用后, 必然一条直路直接莽到边界. 因此 BFS 枚举距离起点不超过 \(k\) 且能走到的点, 若已经到边界则答案为 \(1\), 否则设某个点到边界的距离为 \(x\), 答案就是最小的 \(1+\lceil x/k\rceil\). \(\mathcal O(nm)\).

「AGC 014D」Black and White Tree

  Tag:「C.性质/结论」


  推广一下样例一: 若存在一个点邻接与多余一片叶子, 显然先手必胜. 如果一个点仅邻接一片叶子, 那么先手染白这篇叶子可以抢先手, 因为后手必须立马把叶子染黑. 此时, 状况等价于这个点没有任何邻接点, 所以接着向上归纳即可. 这个归纳等价于找完美匹配, 若存在则后手胜 (经典的完美匹配下后手必胜的情况), 否则先手的确必胜, 不难证明. \(\mathcal O(n)\) 搜一遍即可.

「AGC 014E」Blue and Red Tree *

  Tags:「C.性质/结论」「C.思维」


  失误了属于是. 其实这个结论只要方向对了就很显然: 考虑最后一步操作, 其红边蓝边必然重合. 归纳的, 将这两条边的端点合并, 不断迭代. 若最后只剩一个结点就存在方案. 否则显然也就不存在方案. 用 std::set 之类的东西维护邻接关系, 启发式合并, 可以做到 \(\mathcal O(n\log^2n)\), 当然选用合适的平衡树种类可以做到 \(\mathcal O(n\log n)\).

「AGC 014F」Strange Sorting *

  Tags:「C.性质/结论」「C.思维」


打开题解界面, 不会是真的吧.

  (思路非常 unmotivated, 我无法解读, 甚至无法想象出题人的精神状态.)

  这题的唯一切入点或许是一个很小的 observation: \(p_i=1\) 的位置不会影响其他元素 high 不 high, 也就是说它对我们的排序过程基本没影响.

  猜猜看, 或许可以在值域上归纳? 我们只考虑值域 \([i+1,n]\) 上的元素, 假设在 \(t_{i+1}\) 步后将它们按规则排序, 此时 \(i\) 会出现在序列的某个位置. 当然, 如果恰好是第一个位置, \(t_i=t_{i+1}\), 否则 \(t_i=t_{i+1}+1\). 那现在又有一个问题, 我们似乎需要知道 \(i\) 是否恰好是对 \([i+1,n]\) 排序后的第一个元素.

  仅考虑 \(t_{i+1}>0\) 的情况. 目标是判断 \(t_{i+1}\) 次操作后 \(i\) 是否恰好是 \([i,n]\) 中最前的元素. 设 \(f_{i+1}\) 表示对 \([i+1,n]\) 排序 \(t_{i+1}-1\) 次后的第一个元素. 显然 \(f_{i+1}\neq i+1\). 那么若 \(i\) 落在 \(f_{i+1}\) 和 \(i+1\) 之间, 它就会在下一次排序中被扔到开头. 神谕告诉我们, \(i\) 落在 \(f_{i+1}\) 和 \(i+1\) 之间, 等价于初始序列中, 元素 \(i,i+1,f_{i+1}\) 的出现顺序循环同构于 \([i,i+1,f_{i+1}]\). 也就是说, 操作不会改变 \([i,i+1,f_{i+1}]\) 的循环同构性.

  很 AGC 的是, 我们还需要一个结论才能证明这个断言. 神谕又告诉我们, 在前 \(t_{i+1}-1\) 步中, 当且仅当 \(f_{i+1}\) 处于序列头, \(f_{i+1}\) 才 high.

  考虑反证, 若 \(f_{i+1}\) 不在开头但是 high, 那么在一次操作后, \(f_{i+1}\) 会处于某个原来 high 的元素后边. 显然在这个元素 \(<f_{i+1}\), 则当且仅当这个元素 low 而 \(f_{i+1}\) 又 high 时, 它们会分开. 但分开后 \(f_{i+1}\) 又是非开头的 high, 所以它永远不能成为开头元素, 于条件矛盾.

  证明结论后, 大讨论!

  • \([f_{i+1},i,i+1]\), \(f_{i+1}\) 开头, 三个元素依次为 high, low, low, 操作后仍然同构.
  • \([i+1,f_{i+1},i]\), \(i+1\) 开头, high, low, low, 同理.
  • \([i,i+1,f_{i+1}]\), \(i\) 开头, high, high, low, 同理.
  • 都不是开头元素, low, low, low, 同理.

  证明完所有结论, 从 \(n-1\) 到 \(1\) 递推一边 \(t\) 和 \(f\) 就能求出答案. \(\mathcal O(n)\).

「AGC 015C」Nuske vs Phantom Thnook

  Tag:「水题无 tag」


  树上连通块数 = 结点数 - 导出子图边数. 滚几个二维前缀和就行了. \(\mathcal O(nm)-\mathcal O(1)\).

「AGC 015D」A or...or B Problem

  Tag:「C.细节」


  你甜美的耐心题, 整吐了.

  去掉相同高位. 设 \(b\) 当前的最高为为 \(h\), 注意到如果或和值没有 \(h\) 这位, 上界就不存在了. 所以这提示我们分 \([a,2^h)\) 的部分和 \([2^h,b]\) 的部分讨论.

  若全部选 \([a,2^h)\) 内的数, 可行或和区间显然就是 \([a,2^h)\);

  若全部选 \([2^h,b]\) 内的数, 则 \(b\) 的次高 bit (若存在) 及其低 bit 可以乱选, 次高 bit 以上, \(h\) 以下只能是 \(0\). 将 \(b\) 的次高 bit 后全部置为 \(1\) 得到 \(b'\), 则这部分的或和区间为 \([2^h,b']\);

  还有一种情况是在 \([a,2^h)\) 和 \([2^h,b]\) 内各选一些数. 经过前面的讨论, 我们有端怀疑或和也是一个区间. 下界显然是 \(a+2^h\), 上界显然是 \(2^{h+1}-1\), 难道就是 \([a+2^h,2^{h+1}-1]\)? 那确实就是这样, 证明不难.

  用出色的位运算技巧可以做到 \(\mathcal O(1)\).

「AGC 015E」Mr. Aoki Incubator ^

  Tags:「A.DP-杂项」「C.性质/结论」


  考虑所有碰撞完成的情况, 所有球按 \(v\) 升序排列. 经过简单讨论, 若 \(v_i<v_j<v_k\) 且球 \(i\) 感染过球 \(k\), 那么球 \(j\) 也一定被感染. 因此, 每个球能够感染的是包含自己的一段区间. 预处理出这个区间, 我们将要计数的是: 选择区间, 覆盖 \([1,n]\) 的方案数.

  哈, 前缀和优化一下 DP 就行了. 瓶颈是 \(\mathcal O(n\log n)\) 排序.

「AGC 015F」Kenus the Ancient Greek *

  Tags:「C.性质/结论」「C.思维」


  最大值比较容易打表观察或者构造得出: 不妨令 \(x\le y\), 则最大迭代次数 \(k\) 为最大的满足 \(F_{k-1}\le x\land F_k\le y\) 的 \(k\), 其中 \(F_k\) 表示 Fibonacci 数列的第 \(k\) 项 (\(F_0=F_1=1\)).

  难点在于求方案数. 令 \(f(x,y)\) 表示 \((x,y)\) 需要的迭代次数, \(g(i,j)\) 为 \(f\) 的前缀 \(\max\). 现在, 我们定义 good pair 表示满足 \(f(x,y)=g(x,y)\) 的数对 \((x,y)\). 我们的工作是数出所有满足 \(f(x,y)=k\) 的 good pair 的数量.

  但是 ... 这个转化并没有什么用, good pair 的数量仍然很多. 尝试让 good pair 迭代一次? 我们再定义所有能由 \((k+1)-\)good pair 迭代一次得到的数对为 \(k-\)excellent pair, 目测发现, \(k-\)excellent pair 的数量也许能够接受.

  再观察一下 excellent pair 的位置? 事实上, 数对 \((x,y)~(x<y)\) 是 \(k-\)excellent pair, 当且仅当 \(f(x,y)=k\) 且 \(x,y\le F_{k+2}\). 证明方面, 考虑取任意一个 \((k+1)-\)good pair \((x,px+y)\), 其迭代一次后将变为 \((y,x)\). 如果 \((y,x)\) 不是 excellent pair, 那么应当有 \(x>F_{k+2}\). 我们已知 \(f(F_{k+1},F_{k+2})=k+1\), 而现在有 \(x>F_{k+2}\), 同时 \(f(y,x)=k\), 所以 \(y\ge F_k\), 因此 \(F_{k+2}=F_{k+1}+F_k<px+y\), 这与 \((x,px+y)\) 是 good pair 相矛盾! (注: 官方题解证明这部分貌似写锅了.)

  显然, 我们可以通过 \(k-\)excellent pair 倒推出 \((k+1)-\)excellent pair, 此后, 一个 excellent pair \((x,y)\) 代表着 good pair \((x,y+px)\), 在回答询问时暴力枚举这样的 excellent pair 算贡献就行了. 复杂度 \(\mathcal O(\log^2 V)-\mathcal O(\log V)\).

Solution Set -「AGC 013~015」C~F的更多相关文章

  1. Note -「圆方树」学习笔记

    目录 圆方树的定义 圆方树的构造 实现 细节 圆方树的运用 「BZOJ 3331」压力 「洛谷 P4320」道路相遇 「APIO 2018」「洛谷 P4630」铁人两项 「CF 487E」Touris ...

  2. Diary / Solution Set -「WC 2022」线上冬眠做噩梦

      大概只有比较有意思又不过分超出能力范围的题叭.   可是兔子的"能力范围" \(=\varnothing\) qwq. 「CF 1267G」Game Relics   任意一个 ...

  3. Note/Solution -「洛谷 P5158」「模板」多项式快速插值

    \(\mathcal{Description}\)   Link.   给定 \(n\) 个点 \((x_i,y_i)\),求一个不超过 \(n-1\) 次的多项式 \(f(x)\),使得 \(f(x ...

  4. Solution -「洛谷 P6021」洪水

    \(\mathcal{Description}\)   Link.   给定一棵 \(n\) 个点的带点权树,删除 \(u\) 点的代价是该点点权 \(a_u\).\(m\) 次操作: 修改单点点权. ...

  5. Solution -「APIO 2016」「洛谷 P3643」划艇

    \(\mathcal{Description}\)   Link & 双倍经验.   给定 \(n\) 个区间 \([a_i,b_i)\)(注意原题是闭区间,这里只为方便后文描述),求 \(\ ...

  6. LOJ6003 - 「网络流 24 题」魔术球

    原题链接 Description 假设有根柱子,现要按下述规则在这根柱子中依次放入编号为的球. 每次只能在某根柱子的最上面放球. 在同一根柱子中,任何2个相邻球的编号之和为完全平方数. 试设计一个算法 ...

  7. LOJ6002 - 「网络流 24 题」最小路径覆盖

    原题链接 Description 求一个DAG的最小路径覆盖,并输出一种方案. Solution 模板题啦~ Code //「网络流 24 题」最小路径覆盖 #include <cstdio&g ...

  8. LOJ6001 - 「网络流 24 题」太空飞行计划

    原题链接 Description 有个实验和个仪器,做实验有报酬买仪器有花费.每个实验都需要一些仪器,求最大净收益(实验报酬仪器花费),并输出一组方案. Solution 实验向所需仪器连边,实验的点 ...

  9. 「NowCoder Contest 295」H. Playing games

    还是见的题太少了 「NowCoder Contest 295」H. Playing games 题意:选出尽量多的数使得异或和为$ 0$ $ Solution:$ 问题等价于选出尽量少的数使得异或和为 ...

  10. Libre 6006 「网络流 24 题」试题库 / Luogu 2763 试题库问题 (网络流,最大流)

    Libre 6006 「网络流 24 题」试题库 / Luogu 2763 试题库问题 (网络流,最大流) Description 问题描述: 假设一个试题库中有n道试题.每道试题都标明了所属类别.同 ...

随机推荐

  1. 记录EntityFramework增删改产生的SQL语句

    项目里遇到一个数据交换的需求,申报端和审批端的系统和数据库都不在同一个网段:甲方提供一个msmq队列:我们把申报和审批产生的变化数据用sql记录到xml报文中,通过交换xml文件再解析出sql语句来实 ...

  2. vue项目获取富文本编辑器wangEditor内容导出为word(html转word格式并下载)

    一.开发问题 html-doc-js,只能处理简单的富文本导出为word,对于编辑器中部分图文和样式会不生效,而wangEditor默认设置有下图这么多,所以要自己尝试找替代方案去解决html内容. ...

  3. Redis工具可视化工具Redis Desktop Manager(附安装包)

    前言 redis工具,我相信每个开发都需要,如果每次查都去client执行指令,我怕查完之后,老大就要发版咯.我之前一直用的Redis可视化工具RedisDesktopManager,总觉得差点意思, ...

  4. 基于surging的木舟平台如何构建起微服务

    一.概述 木舟平台分为微服务平台和物联网平台, 上面几篇都是介绍如何通过网络组件接入设备,那么此篇文章就细致介绍下在木舟平台下如何构建微服务. 木舟 (Kayak) 是什么? 木舟(Kayak)是基于 ...

  5. unique:数组去重,返回一个新数组

    function unique(arr){ if(!isArrayLink(arr)){ //不是类数组对象 return arr } let result = [] let objarr = [] ...

  6. C# 开发的数据采集及云端监控系统

    前言 推荐C#语言开发的堤坝渗透地质数据采集及云端监控系统.希望本文能够为大家提供有价值的信息和参考. 项目介绍 使用数十个 .NET 客户端控制硬件设备进行工作,采集数据并进行处理. 管理人员通过 ...

  7. Java Study For Five Day( 面向对象一)

    面向对象 1.面向对象的概念 2.理解面向对象 *面向对象其实是相对面向过程而言的,面向对象和面向过程都是一种思想,它们所强调的内容不一样. *面向对象:强调的是功能的行为,将功能进行了封装成了对象, ...

  8. 理解Flink之一编译Flink-1.11.1

    下载源码 git clone -b release-1.11.1 https://github.com/apache/flink.git --depth=1 flink-1.11.1 编译 mvn c ...

  9. ZCMU-1144

    简单问题: 就只是如何降低时间的问题罢了:本来这种方法以前学过但是没怎么用所以不太灵活. #include<stdio.h> #define maxn 1000010 int sum[ma ...

  10. 修改data数据后页面未更新渲染

    只需添加 this.$forceUpdate() 在修改数据后执行即可 this.$forceUpdate()