Skip to content

Mock Contest 2 -- The Technique Gauntlet

Time limit: 2.5 hoursTarget audience: Codeforces 1400-1800

This contest tests your technique toolkit. Each problem deliberately isolates a core algorithmic skill so the result is diagnostic: if D is the wall, you need data-structure work; if E is the wall, graph modeling; if F is unreachable, that is the stretch goal of this set.

Set a timer. No editorials until time is up. No template lookups mid-contest — if you cannot write a BIT or topo-sort from memory, that result is part of the diagnostic.

Quick Revisit

Problems

#ProblemExpected DifficultyTime TargetCore Technique
ACF 1623C -- Balanced Stone Heaps140015 minBinary search on answer -- reverse simulation
BCF 1579E2 -- Array Optimization by Deque (Hard)150020 minGreedy + BIT/merge sort -- inversion counting
CCF 1498C -- Planar Reflections160025 minDP -- model particle decay across planes
DCF 1354D -- Multiset170030 minBinary Indexed Tree -- k-th element query
ECF 1385E -- Directing Edges180030 minTopological sort -- orient undirected edges in DAG
FCF 1175E -- Minimal Segment Cover190030 minSparse table / binary lifting on intervals

Diagnostic Read-out

A single mock cannot reliably estimate rating, but it can locate the next gap. Use the table below as a diagnostic, then drill the specific area below.

Problems SolvedDiagnosticWhere to focus next
A onlyComfortable with one technique (binary search on answer); breadth still missingDrill BIT and basic DP on the practice ladders
A + BGood fundamentals; struggling with DP modelingPush into DP territory — Mock 2's C and Chapter 4
A + B + CSolid mid-range; data structures are the next ceilingBIT and segment tree drills, then attempt D
A + B + C + DStrong toolkit; combining techniques is the bottleneckMulti-technique problems (graph + DP, sweep + BIT)
A through EBroad technique coverage at this bandMove on to harder problems and Div 1 attempts
All 6This set no longer diagnoses youTry Mock 3 (speed) or Educational Round virtuals

Technique Diagnostic

Use your results to identify gaps:

ProblemIf You Couldn't Solve ItStudy Area
ABinary search on answerComplexity Cheatsheet -- look for monotonic properties
BInversion counting with BITData Structure Selection Guide
CDP state designDP vs Greedy Guide
DBIT operationsData Structure Selection Guide
ETopological sort + constructionBFS vs DFS Guide
FSparse table / binary liftingAdvanced -- study interval covering with jump pointers

Post-Contest Reflection

After the timer ends, answer in your Mistake Journal:

  1. Technique gaps: Which techniques did you know in theory but fail to implement? Those are your highest-ROI study targets.
  2. Modeling time: How long did it take you to see what technique each problem needed? Fast recognition = fast solves.
  3. Code from memory: Could you write BIT/topo-sort/segment tree without looking anything up? If not, drill those templates.
  4. Partial progress: For unsolved problems, how far did you get? Did you have the right idea but wrong implementation?
  5. Ordering strategy: Did you solve them in order? Would skipping a hard problem and coming back have helped?

Detailed Walkthrough (read after attempting)

Problem A -- Balanced Stone Heaps

Binary search on the minimum value of the final array. For a candidate answer mid, simulate the process in reverse (from last pile to first). Each pile with value > mid can distribute stones backward to earlier piles (undo the forward operation). If all piles can reach >= mid, the answer is feasible.

Key insight: processing in reverse lets you "undo" the giving operation. Common mistake: processing forward instead of backward, or integer overflow on stone counts.

Problem B -- Array Optimization by Deque

For each element, you choose to push_front or push_back. To minimize inversions, count how many existing elements are greater (push_front cost) vs. smaller (push_back cost). Pick the cheaper side. Use a BIT/Fenwick tree for efficient counting.

Key insight: each decision is locally optimal -- greedy works because future elements don't affect past inversion counts. Common mistake: not compressing coordinates before using BIT.

Problem C -- Planar Reflections

DP where state = (remaining planes, current decay countdown). A particle hitting a plane splits: one continues forward with same countdown, one reflects backward with countdown-1. Track how many particles are alive. Since countdown <= k <= 1000 and planes <= 1000, the DP table is manageable.

Key insight: particles with countdown = 1 don't split further, which bounds the state space. Common mistake: trying to simulate all particles explicitly (exponential blowup).

Problem D -- Multiset

Maintain a BIT over values 1..n. For additions, update BIT at position a_i. For deletions (k-th smallest), binary search on the BIT prefix sums to find the k-th element, then remove it.

Key insight: BIT prefix sum = count of elements <= x, so binary search on prefix sums finds k-th smallest in O(log^2 n) or O(log n) with BIT walk. Common mistake: using a slow k-th element query (nested binary search instead of BIT descent).

Problem E -- Directing Edges

First, build a graph with only the directed edges. If it has a cycle, output "NO". Otherwise, topologically sort the directed graph. Then orient each undirected edge from earlier to later in the topological order -- this guarantees no cycles.

Key insight: undirected edges oriented along topological order can never create cycles. Common mistake: forgetting that the directed-only graph might already have cycles.

Problem F -- Minimal Segment Cover

Preprocess: for each left endpoint x, find the farthest right endpoint reachable by any segment starting at or before x. Then build a binary lifting table: jump[k][x] = farthest right reachable from x using 2^k segments. To answer a query [l, r], greedily jump from l using the largest powers of 2 first, counting segments.

Key insight: this is the classic "minimum intervals to cover a range" problem, accelerated from O(n) per query to O(log n) with sparse table. Common mistake: off-by-one in the lifting table boundaries, or not merging overlapping initial segments correctly.


See also: Mock Contest 1 | Mock Contest 3 (Speed) | Mistake Journal | Practice Ladder 1400-1700

Built for the climb from Codeforces 1100 to 2100.