Translation Notice
This article was machine-translated using DeepSeek-R1.
- Original Version: Authored in Chinese by myself
- Accuracy Advisory: Potential discrepancies may exist between translations
- Precedence: The Chinese text shall prevail in case of ambiguity
- Feedback: Technical suggestions regarding translation quality are welcomed
A - A Unique Letter
Problem Summary
Given a string $S$ of length 3.
Output any character that appears exactly once in $S$ (e.g., in abc
, any of the three characters can be the answer).
If no such character exists, output -1
.
Constraints:
- $S$ has length 3
- $S$ consists of lowercase English letters.
Input Format
$S$
Output Format
Output any valid answer.
Samples
$S$ | Output |
---|---|
pop |
o |
abc |
a /b /c |
xxx |
-1 |
Analysis
Let the three input characters be a
, b
, c
.
- If $a = b = c$, output
-1
. - Check for two equal characters in different positions:
xxy
pattern ($a = b$): output $c$xyx
pattern ($a = c$): output $b$yxx
pattern ($b = c$): output $a$xyz
pattern (all distinct): output any character
In the code, the last two cases are merged (handled by a single else
, outputting $a$).
Code
|
|
B - Better Students Are Needed!
Problem Summary
$N$ candidates took an exam.
Candidate $i$ scored $A_i$ in math and $B_i$ in English.
The company selects candidates in three stages:
- Top $X$ math scores are selected.
- From remaining candidates, top $Y$ English scores are selected.
- From remaining candidates, top $Z$ total scores (math + English) are selected.
Note: Candidates with equal scores are ordered by their IDs.
Output all selected candidate IDs in ascending order.
Constraints:
$1\le N\le 1000$
$0\le X,Y,Z\le N$
$1\le X+Y+Z\le N$
$0\le A_i,B_i\le 100$
Input Format
$N~X~Y~Z$
$A_1~A_2~\dots~A_N$
$B_1~B_2~\dots~B_N$
Output Format
Output selected candidate IDs in ascending order, one per line.
Analysis
Two approaches:
- Use
pair<int, int>
for candidates and sort vectors/use priority queues for each selection stage. - Use a struct to store candidate data and sort three times with different criteria.
See Code 1 and Code 2.
Code
Code 1 (vector + sort)
|
|
Code 2 (struct-based sorting)
|
|
C - Changing Jewels
Problem Summary
Takahashi has an level $N$ red jewel.
He can perform the following operations any number of times:
- Convert a level $N$ red jewel into “1 level $N-1$ red jewel + $X$ level $N$ blue jewels”.
- Convert a level $N$ blue jewel into “1 level $N-1$ red jewel + $Y$ level $N-1$ blue jewels”.
What’s the maximum number of level 1 blue jewels he can obtain?
Constraints:
$1\le N\le 10$
$1\le X,Y\le 5$
Input Format
$N~X~Y$
Output Format
Output the maximum count of level 1 blue jewels.
Samples
$N$ | $X$ | $Y$ | Output |
---|---|---|---|
$2$ | $3$ | $4$ | $12$ |
$10$ | $5$ | $5$ | $3942349900$ |
Note: Beware of 32-bit integer overflow.
Analysis
To maximize level 1 blue jewels, process jewels from higher levels downwards.
Maintain two variables: red
(level $k$ red jewels) and blue
(level $k$ blue jewels).
For each level from $N$ down to 2:
- Convert all red jewels to lower-level red and blue jewels.
- Convert all blue jewels to lower-level red and blue jewels.
Time complexity: $\mathcal O(N)$.
Code
|
|
D - Draw Your Cards
Problem Summary
Process $N$ cards with unique numbers $P_1,\dots,P_N$ in order.
For each card $P_i$:
- Find the topmost card in existing piles that is $\ge P_i$. Place $P_i$ on it.
- If no such pile exists, create a new pile.
- If a pile reaches $K$ cards, remove all its cards immediately.
Output the time each card is removed (or -1
if never removed).
Constraints:
$1\le K\le N \le 2\times 10^5$
$P$ is a permutation of $(1,2,\dots,N)$.
Analysis
Use a Union-Find structure to track parent cards and set-based operations to find the correct pile.
Maintain a set
of current pile tops for efficient lookups.
For each card, track the pile size and update when merged.
Time complexity: $\mathcal O(N \log N)$.
Code
|
|
E - At Least One
Problem Summary
Given $M$ and $N$ pairs $(A_i,B_i)$, count all consecutive subarrays $[l,r]$ of $[1,M]$ such that for each $i$, $A_i$ or $B_i$ is in $[l,r]$.
Let $f(k)$ be the count of valid subarrays of length $k$. Output $f(1),\dots,f(M)$.
Constraints:
$1\le N\le 2\times 10^5$
$2\le M\le 2\times 10^5$
$1\le A_i < B_i\le M$
Analysis
Use a sliding window approach. For each $l$, find the smallest $r$ where all pairs are covered.
Preprocess each position’s contribution to coverage and track counts using difference arrays.
Time complexity: $\mathcal O(N + M)$.
Code
|
|
F - Find 4-cycle
Problem Summary
Given a bipartite graph between sets $U$ and $V$, find any 4-cycle (four nodes forming a cycle). Output the nodes or -1
.
Constraints:
$2\le |U| \le 3\times 10^5$
$2\le |V| \le 3000$
$4\le M\le \min(|U|\times|V|,3\times 10^5)$
Analysis
Exploit the small size of $V$. For each node in $V$, track pairs of nodes in $U$ connected to it. Use a matrix to record pairs and detect overlaps.
Time complexity: $\mathcal O(T^2)$, feasible due to $T \le 3000$.
Code
|
|