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 - Square Inequality
Problem Statement
Given three integers $A$, $B$, and $C$, determine if $A^2 + B^2 < C^2$ holds.
$0 \le A,B,C \le 1000$
Input Format
$A~B~C$
Output Format
Print Yes
if $A^2 + B^2 < C^2$; otherwise, print No
.
Samples
$A$ | $B$ | $C$ | Output |
---|---|---|---|
$2$ | $2$ | $4$ | Yes |
$10$ | $10$ | $10$ | No |
$3$ | $4$ | $5$ | No |
Analysis
Directly compute according to the problem statement.
Code
|
|
B - Intersection
Problem Statement
Given two sequences of length $N$: $A = (A_1, A_2, A_3, \dots, A_N)$ and $B = (B_1, B_2, B_3, \dots, B_N)$. Find the number of integers $x$ satisfying:
- For all $1 \le i \le N$, $A_i \le x \le B_i$.
$1 \le N \le 100$
$1 \le A_i \le B_i \le 1000$
Input Format
$N$
$A_1~A_2~\dots~A_N$
$B_1~B_2~\dots~B_N$
Output Format
Print the answer.
Samples
Sample Input1
|
|
Sample Output1
|
|
Possible $x$ values: $3$, $4$, $5$.
Sample Input2
|
|
Sample Output2
|
|
No valid $x$ exists.
Sample Input3
|
|
Sample Output3
|
|
Analysis
The constraints can be decomposed into:
- For all $1 \le i \le N$, $A_i \le x$.
- For all $1 \le i \le N$, $x \le B_i$.
This simplifies to $\max(A) \le x \le \min(B)$. The valid count is $\max(0, \min(B) - \max(A) + 1)$.
Code
|
|
C - IPFL
Problem Statement
Given a string $S$ of length $2N$ consisting of uppercase letters. Process $Q$ queries. Each query consists of three integers $T_i, A_i, B_i$:
- If $T_i = 1$: swap the $A_i$-th and $B_i$-th characters of $S$.
- If $T_i = 2$: swap the first $N$ and last $N$ characters of $S$.
Output $S$ after all queries.
$1 \le N \le 2 \times 10^5$
$|S| = 2N$
$1 \le Q \le 3 \times 10^5$
$1 \le T_i \le 2$, $1 \le A_i < B_i \le 2N$ if $T_i = 1$; $A_i = B_i = 0$ if $T_i = 2$.
Input Format
$N$
$S$
$Q$
$T_1~A_1~B_1$
$T_2~A_2~B_2$
$\hspace{18pt}\vdots$
$T_Q~A_Q~B_Q$
Samples
Sample Input1
|
|
Sample Output1
|
|
$\text{FLIP} \to \text{IPFL} \to \text{LPFI}$
Sample Input2
|
|
Sample Output2
|
|
Analysis
The $\mathcal O(NQ)$ simulation approach would TLE. Optimize by tracking flip state:
- Maintain
flipped
flag. For $T_i = 2$, toggleflipped
. - For $T_i = 1$, adjust indices based on
flipped
status to compute actual positions.
Time complexity: $\mathcal O(N + Q)$.
Code
|
|
D - RGB Coloring 2
Problem Statement
Given a simple undirected graph with $N$ vertices and $M$ edges. Count valid colorings using three colors where adjacent vertices have different colors.
$1 \le N \le 20$
$0 \le M \le \frac{N(N-1)}{2}$
Input Format
$N~M$
$A_1~B_1$
$A_2~B_2$
$\hspace{12pt}\vdots$
$A_M~B_M$
Output Format
Print the answer.
Samples
Sample Input1
|
|
Sample Output1
|
|
Valid colorings: RGB
, RBG
, GRB
, GBR
, BRG
, BGR
.
Sample Input2
|
|
Sample Output2
|
|
Sample Input3
|
|
Sample Output3
|
|
Sample Input4
|
|
Sample Output4
|
|
Analysis
For each connected component, count valid colorings via DFS. Multiply results across components. Total attempts are bounded by $3 \times 2^{N-1}$.
Code
Seems no one noticed that unsigned int
could be used…
|
|
E - Permutation
Problem Statement
Count permutations of $(1, 2, \dots, N)$ satisfying:
- For each $1 \le i \le M$, among the first $X_i$ elements, at most $Z_i$ are $\le Y_i$.
$2 \le N \le 18$
$0 \le M \le 100$
$1 \le X_i, Y_i < N$
$0 \le Z_i < N$
Input Format
$N~M$
$X_1~Y_1~Z_1$
$X_2~Y_2~Z_2$
$\hspace{18pt}\vdots$
$X_M~Y_M~Z_M$
Output Format
Print the count.
Samples
Sample Input1
|
|
Sample Output1
|
|
Valid permutations: $(1,2,3)$, $(2,3,1)$, $(3,1,2)$, $(3,2,1)$.
Sample Input2
|
|
Sample Output2
|
|
Sample Input3
|
|
Sample Output3
|
|
Analysis
Use bitmask DP. Let dp[mask]
represent the number of valid ways to select the subset mask
. For each bit added, check constraints. Time complexity: $\mathcal O(2^N \cdot (N + M))$.
Code
|
|