25_1_4 Hello 2025
1. Hello 2025
A. MEX Table(800)
(constructive algorithms)(math)
Ques
题意
One day, the schoolboy Mark misbehaved, so the teacher Sasha called him to the whiteboard.
Sasha gave Mark a table with
where
Sasha is not interested in how Mark arranges the numbers, so he only asks him to state one number — the maximum sum of MEX across all rows and columns that can be achieved.
For example:
, since does not belong to the array. , since and belong to the array, but does not. , since , , , and belong to the array, but does not.
Input
Each test contains multiple test cases. The first line contains a single integer
The first line of each test case contains two integers
Output
For each test case, output the maximum possible sum of
Example
1 | 3 |
1 | 2 |
Note
In the first test case, the only element is
In the second test case, the optimal table may look as follows:
Then $\sum\limits{i = 1}^{n} \operatorname{mex}({a{i,1}, a{i,2}, \ldots, a{i,m}}) + \sum\limits{j = 1}^{m} \operatorname{mex}({a{1,j}, a{2,j}, \ldots, a{n,j}}) = \operatorname{mex}({3, 0}) + \operatorname{mex}({2, 1})
Ans
画图模拟下,马上就能出
1 | void solve(){ |
B. Gorilla and the Exam(1000)
(greedy)(sortings)
Ques
题意
Due to a shortage of teachers in the senior class of the “T-generation”, it was decided to have a huge male gorilla conduct exams for the students. However, it is not that simple; to prove his competence, he needs to solve the following problem.
For an array
- take two integers
and , such that , and let be the $\min(bl, b{l+1}, \ldots, b_r)$; then - remove all such
that and from the array, the deleted elements are removed, the indices are renumerated.
You are given an array
Help the gorilla to determine the smallest value of
Input
Each test contains multiple test cases. The first line contains a single integer
The first line of each set of input data contains two integers
The second line of each set of input data contains
It is guaranteed that the sum of the values of
Output
For each set of input data, output a single integer on a separate line — the smallest possible value of
Example
1 | 6 |
1 | 1 |
Note
In the first set of input data,
In the second set of input data, you can change the second number to
Ans
尽量不要想着排序map的key
1 | void solve(){ |
C. Trip to the Olympiad(1500)
(bitmasks)(constructive algorithms)(greedy)(math)
Ques
题意
In the upcoming year, there will be many team olympiads, so the teachers of “T-generation” need to assemble a team of three pupils to participate in them. Any three pupils will show a worthy result in any team olympiad. But winning the olympiad is only half the battle; first, you need to get there…
Each pupil has an independence level, expressed as an integer. In “T-generation”, there is exactly one student with each independence levels from
Your task is to choose any trio of students with the maximum possible team independence.
Input
Each test contains multiple test cases. The first line contains a single integer
The first line of each test case set contains two integers
Output
For each test case set, output three pairwise distinct integers
Example
1 | 8 |
1 | 1 2 0 |
Note
In the first test case, the only suitable triplet of numbers (
In the second test case, one of the suitable triplets is (
Ans
这道题的核心是看二进制最高不同位
对于第i位:
- 三个数这一位全相同(要么全是0 要么全是1),这一位贡献0
- 不是全相同,即三对异或里刚好有两对不同,贡献
也就是说只要三个数这一位不是全一样,这一位就拿满分
现在看 l 和 r,比方说 l = 6 = 00110,r = 22 = 10110
从最高位看,最高不同位是第4位。当然,比第4位更高的位,整个区间[l,r]里的数都是一样的,不可能贡献,所以我们最多只能让0 1 2 3 4位贡献,即让0…k这些位每一位都产生贡献,所以理论上最大值的上限应该是
那怎么构造呢?
我们可以找到跨过最高不同位边界的两个连续数,比方说01111和10000,这两个数0…4位每一位都相反,那么接下来我们只需在这个区间随便取一个数
思路已经很明了了,那我们该怎么写呢?
有个特别好的代码int a = l | ((1<<k)-1);
这行代码的意思是把 l 的低 k 位全部变成 1,比方说 l = 6:
1 | l = 00110 |
所以a = 15,b = a+1 = 16
而对于第三个数,如果 a 已经等于 l 了,第三个数不能再选 l 了,那就选r,反之选l
1 | void solve(){ |

