Mxiaocao 刷题博客总拆解(第一版)
说明:重点不是复述题解,而是提炼:真正要学什么、下次看到什么条件应该触发什么思路、要不要重做。 重做优先级:高 = 七月冲分重点;中 = 保持手感;低 = 看一眼即可;暂缓 = 当前可先放。 # 题目 来源 真正要学的点 下次触发器 重做 1 A. MEX Table(800) 1. Hello 2025.md MEX 最大化通常先盯住 0;0 同时只能给一行一列提供贡献,答案由较长维度决定。 看到 MEX + 网格 + 只求最大值,不要构造,先想 0 放哪里、0 能影响几组。 低 2 B. Gorilla and the Exam(1000) 1. Hello 2025.md 把操作目标转化成”保留多少种数”:统计频率,优先用 k 次修改消掉出现次数少的种类。 看到可修改元素 + 最小化剩余种类/操作次数,先按频率排序。 中 3 C. Trip to the Olympiad(1500) 1. Hello 2025.md 位运算最大化要按最高不同位拆;高位相同没有贡献,最高不同位以下尽量全贡献。 看到三个数/区间/XOR 最大值,先找 l,r 的最高不同...
Team Weekly Contest 2026-5-10
Team Weekly Contest 2026-5-10题目难度:AG -> J -> EBI -> LKHDCF A. Anxiety at the restaurantQues题意 Margot Finch goes out to eat. A lot. Like, way too much. Birthdays, Fridays, random Wednesdays — she always finds a reason. And every time, the same thing happens: everyone at the table does their own math, puts their money in the middle, and walks out like everything is fine. It is never fine. The waiter always catches her at the door. Every. Single. Time. “Hey, we’re still a little short.”...
25_2_18 Educational Codeforces Round 174 (Rated for Div. 2)
1. A. Was there an Array?门钥匙 口头表述给你一个长度为n的整数数组a,但是这个数组a本身没有告诉你,我们只知道它中间每个位置的相等情况:对于每个位置i,其中2 ≤ i ≤ n-1,如果 a[i-1] == a[i] == a[i+1],那么 b[i] = 1,反之b[i] = 0。现在题目给你的是数组 b2, b3, ..., b(n-1),让你判断:是否存在某个整数数组 a,它能够产生这个给定的 b 数组。如果存在,输出YES,反之NO。 题解思路不复杂,发现是101的就说明有错 1234567891011121314void solve(){ int n; cin >> n; vector<int> b(n-2); for(int i = 0;i < n-2;++i) cin >> b[i]; for(int i = 0;i < n-4;++i){ if(b[i] == 1 && b[i+2] == 1){ cout <&...
AtCoder Daily Compile 2
Mxiaocao::Daily_Compile() T1111. D - Card Pile Query门钥匙 口头表述有n张牌,n个牌堆,一开始,牌堆i中只有牌i。现在要进行q次操作,每次操作,都会给你c,p两个数,即找到牌c的那一堆,把牌c和它上面的所有牌一起拿起来,保持顺序不变,放到牌p上面。题目保证牌c和牌p不在同一堆,且p在牌堆的最上面。最后要求你输出每个牌堆分别还剩多少牌 题解我们可以把每张牌看成一个节点,只记录这张牌下面压着哪张牌,用down来记录,当然,如果down[x] = 0,说明x是某一堆的最底牌。比如一堆牌从下往上看是3 1 4,那么down[4] = 1,down[1] = 3,down[3] = 0。那么我们怎么统计每堆有几张牌呢,每张牌顺着down一直往下找,找到最底下那张牌root,然后res[root]++,返回res。这个find是不是很眼熟,没错,就是借鉴了并查集的思想 1234567891011121314151617181920212223242526void solve(){ int n,q; cin >> ...
codeforces daily compile 1
Mxiaocao::Daily_Compile() T1-T41. C1. Equal Multisets (Easy Version)Ques门钥匙 题意 This is the easy version of the problem. The difference between the versions is that in this version, the array is guaranteed to be a permutation. You can hack only if you solved all versions of this problem. Given an array of size , and a parameter , an array is called cool if the following conditions hold: For each from to , the array $[a{i-k+1},a{i-k+2},\ldots,ai][b{i-k+1},b_{i-k+2},\ldots,b_i]$. You are ...
AtCoder Daily Compile 1
Mxiaocao::Daily_Compile() T1-T101. C - Drop Blocks门钥匙 QuesProblem Statement There are cells arranged in a row from left to right. Initially, no blocks are placed in any cell. You are given queries, so process them in order. Each query is one of the following two types: 1 x: Place block in the -th cell from the left. Then, if every cell has at least block, remove block from every cell. 2 y: Output the number of cells that have at least blocks. Constraints All input values are inte...
26_5_30 Codeforces Round 1101 (Div. 2)
26_5_30 Codeforces Round 1101 (Div. 2)A. ConvergenceQues门钥匙 题意 Alice is inviting her friends to a party to eat cakes. However, each friend may not be at the same place, so everyone has to meet up at the same location first. Alice has friends, where the -th friend is at position . To make everyone be at the same place, Alice has to make multiple group calls. Unfortunately, the signal is weak, and Alice can only call other people at a time. Being a good person, Alice doesn’t want her friends ...
SOS DP
SOS dp在算法竞赛中,处理涉及位运算的问题时,我们通常会遇到一类需求:给定一个数组,要求出每个二进制状态的所有子集的权值之和 当然,首先我们要解释几个变量,这样方便我们后续的学习: n 表示二进制位数,也可以理解成“集合里有多少个元素”。如果:n = 3,那么状态数量就是:1 << n,也就是:2^3 = 8,状态范围是:000 ~ 111 mask 表示一个状态,也就是一个集合。比如:mask = 10110表示第 1、2、4 位被选中。for(int mask = 0;mask < (1 << n);mask++) 意思是枚举所有状态。 sub 表示 mask 的某个子集。比如:mask = 110,它的 sub 可以是:000、010、100、110。for(int sub = mask; ;sub = (sub - 1) & mask) 表示枚举 mask 的所有子集。 sup 表示 mask 的超集。如果:mask = 010,那么它的超集可以是:010、011、110、111。意思是:包含 mask 的集合。 bit...
6.4 树状数组(BIT)
6.4 树状数组/BIT树状数组本质上可以理解为一个“进行分段求和”的数组,且具备树的物理性质。树状数组可以高效地计算数列的区间和,并支持单点及区间的动态修改操作。这种结构不仅精巧,而且常数极小,是算法竞赛中的绝对大杀器。 但是在正式学习树状数组之前,我们需要先掌握一个核心的二进制底层操作:lowbit。 lowbit(x) 是整个数据结构的灵魂,它表示将 x 在二进制下仅保留最低位的 1 所表达的二进制数。例如: lowbit((10010)) = (10) lowbit((1010010100)) = (100) 它的实现方式也是非常的直接,利用计算机底层补码的性质(即负数是按位取反再加一),直接返回 x & -x 即可。即: 123int lowbit(int x) { return x & (-x);} 交互演示:在线演示 BIT 的树形结构、add 更新与 sum 查询过程 1. 单点修改 区间查询在算法竞赛中,我们经常会遇到这样一种极度恶心的场景: 系统维护着一个长度为 的数组( 往往高达 甚至 ),并且会在任意时刻交替向你发送两种指...
5.2.6 Floyd
5.2.6 Floyd适用条件:多源最短路(求任意两点间的最短距离)、允许存在负权边。 [注]:由于其时间复杂度高达 ,纯正的“暴力美学”,只适用于图极其微小的情况(通常顶点数 )。但在小图里,它是最好写、最不容易出错的算法,核心代码只有五行! Floyd 算法与 Dijkstra、SPFA 最大的不同在于,它不是用来求“单源”(从一个固定起点出发)的,而是一次性把地图上任意两个村庄之间的最短路全部算出来。 有个极其贴切的现实模型,即“航班中转(找中间人)”。 假设你要从城市 飞往城市 ,当前直飞的机票要 1000 块。此时,你考虑去城市 作为一个“中转站”。你查了一下,从 飞 只要 300 块,从 飞 只要 400 块。那么 。此时,你找到了更便宜的路线。Floyd 算法的本质,就是把地图上的每一个城市,都轮流当作一次中转站,去尝试优化所有航班的票价。 必备概念只需要记下一个最核心的数据结构: dist[N][N]:一个二维数组(邻接矩阵),存储的是目前从点 到点 的最短距离。 起初,它只记录“直飞”的距离(也就是输入的边)。 随着算法运行,它会不断被“中转航...
