Skip to content

Speed Implementation Drills

Timed implementation practice for contest warm-up. Code each from scratch -- no references, no copy-paste. Track your times and watch them shrink.

Quick Revisit

  • SKILL FOCUS: timed implementation -- muscle memory for contest templates
  • DIFFICULTY: Tier 1 (easy) to Tier 3 (advanced)
  • PROBLEMS: 30 drills across 3 tiers
  • PREREQUISITE: Common Templates

How to Use

  1. Pick a drill matching your current practice focus
  2. Start a timer (use your phone or codeforces custom invocation)
  3. Code the solution from scratch in your contest IDE
  4. Test on 2-3 small inputs
  5. Compare against the target time
  6. If over target: practice daily until you hit it consistently

The goal isn't memorization -- it's muscle memory. When segment tree setup takes 2 minutes instead of 8, you have 6 extra minutes for thinking during a contest.


Tier 1: Foundations (Target: Under 3 Minutes)

These are the bread and butter. If any of these take more than 3 minutes, drill them daily.

#DrillTargetWhat to Code
1Sieve of Eratosthenes1:30Prime sieve up to N, output count of primes
2Binary Search1:00lower_bound and upper_bound on sorted array
3Prefix Sums (1D)1:00Build prefix array, answer L..R sum queries
4Prefix Sums (2D)2:30Build 2D prefix, answer submatrix sum queries
5DFS (recursive)1:30Count connected components in undirected graph
6BFS (shortest path)2:00Shortest path on unweighted graph, print distance
7BFS on Grid2:30Shortest path in grid with obstacles
8Sorting + Custom Comparator1:00Sort structs by multiple fields
9Two Pointers1:30Count pairs with sum <= K in sorted array
10Sliding Window2:00Maximum sum subarray of length K

Tier 2: Intermediate (Target: Under 5 Minutes)

These show up in Div2 C/D problems. Fluency here is the difference between solving in-contest vs. upsolving.

#DrillTargetWhat to Code
11DSU (Union-Find)2:30Path compression + union by rank, count components
12BIT / Fenwick Tree3:00Point update + prefix sum query
13Segment Tree (point update)4:00Build + point update + range sum query
14Dijkstra4:00Shortest path with priority queue, print distances
15Topological Sort (Kahn's)3:00BFS-based topo sort, detect cycle
160/1 Knapsack3:30Space-optimized 1D DP
17LIS (O(n log n))3:00Longest increasing subsequence with lower_bound
18Modular Inverse2:00Fermat's little theorem, mod exponentiation
19Combinatorics Setup3:00Precompute factorials + inverse factorials, nCr queries
20String Hashing3:30Polynomial hash with prefix array, substring comparison

Tier 3: Advanced (Stretch Goal — Under 8 Minutes)

These separate 1700+ from 2000+. Each one saves massive time when it appears in a contest.

Stretch-goal note. The targets in this tier — 5-8 minutes for Dinic, centroid decomposition, suffix array — are aspirational benchmarks, not pass/fail bars. Hitting them consistently puts you at strong-division-1 implementation speed. If you are at 12-15 minutes after honest practice, that is normal and not a sign you are failing the drill.

#DrillTargetWhat to Code
21Lazy Segment Tree7:00Range add + range sum query
22LCA with Binary Lifting6:00Preprocess in O(n log n), query in O(log n)
23Centroid Decomposition7:00Find centroids, build centroid tree
24Convex Hull6:00Andrew's monotone chain algorithm
25KMP4:00Build failure function, find all occurrences
26Z-Function3:30Build Z-array, find all pattern occurrences
27SCC (Kosaraju's)6:00Two-pass DFS, output components
28Max Flow (Dinic's)8:00BFS layering + DFS blocking flow
29Suffix Array (O(n log^2 n))7:00Rank-based construction with sorting
30Matrix Exponentiation5:00Matrix multiply + fast power for linear recurrence

My Times

Track your progress here. Date each attempt. Speed without correctness is not contest fluency — record the bug type if your code did not pass, and whether you wrote it from memory or had to peek.

Columns:

  • Time — wall-clock minutes:seconds.
  • From memory? Y/N — were references closed for the entire attempt?
  • Bug typeclean, off-by-one, overflow, init, transition, IO, other. Blank if AC on first run.
DrillAttempt 1 (time / mem? / bug)Attempt 2Attempt 3Attempt 4Attempt 5
Sieve
Binary Search
Prefix Sums 1D
Prefix Sums 2D
DFS
BFS
BFS Grid
Custom Sort
Two Pointers
Sliding Window
DSU
BIT
Segment Tree
Dijkstra
Topo Sort
0/1 Knapsack
LIS
Mod Inverse
Combinatorics
String Hash
Lazy Seg Tree
LCA
Centroid
Convex Hull
KMP
Z-Function
SCC
Max Flow
Suffix Array
Matrix Exp

Weekly Drill Schedule

For maximum improvement, follow this rotation:

DayFocusDrills
MondayFoundations#1-5 (all Tier 1)
TuesdayData Structures#11-13 (DSU, BIT, SegTree)
WednesdayGraphs#6, #14, #15 (BFS, Dijkstra, TopoSort)
ThursdayDP + Math#16-19 (Knapsack, LIS, Mod, Combinatorics)
FridayAdvancedPick 2 from Tier 3
WeekendWeak spotsRepeat any drill where you're over target

After 2 weeks of daily drilling, most people cut their implementation time in half. That's 10-15 extra minutes per contest -- often the difference between solving D or not.


See also: Common Templates | Data Structure Selection Guide | Practice Ladders

Built for the climb from Codeforces 1100 to 2100.