Everything contest-only in one place: the pre/during/post-contest checklist, the statement-pattern lookup, common mistakes, and small tricks. Nothing here is a technique on its own — each row points at the note that actually explains it.

Checklist

Before the contest

  • Template compiles; fast I/O; debug macro prints to stderr only (C++ for CP).
  • Stress-test script ready: brute force, generator, checker (Debugging).
  • Team: reference document printed, roles agreed (Contest Strategy).

Reading

  • Read every problem’s statement and constraints; note the easiest by the scoreboard.
  • For each problem: input limits target complexity (see Techniques by Pattern below).
  • Re-read samples; solve one sample by hand before designing.

Before coding

  • I can state the algorithm in two sentences and its complexity fits.
  • I know why it is correct (or I have a brute force to stress it).
  • Edge cases listed: , empty, all equal, max values, negatives, disconnected.

Before submitting

  • long long where needed; mod applied everywhere.
  • Multi-test: every global reset.
  • Array sizes and indices checked; no debug output on stdout.
  • Ran samples and a max test for time.
  • Output format (spaces, newlines, YES/Yes, precision).

After a wrong answer

  • Re-read the statement; check every item above, and the Common Mistakes table below.
  • Stress test against the brute force on small random inputs.
  • Explain the solution to a teammate (or out loud); check the proof.

After the contest

  • Upsolve every problem you could almost solve; write the missing idea down (Problem Set).

Techniques by pattern

Statement pattern first technique to try. Constraints decide as much as wording: see Complexity and Analysis for “what fits in one second”.

By wording

The statement saysTry firstNote
minimise the maximum / maximise the minimumbinary search on the answerBinary Search
minimum number of operations, answer looks tinyprove the answer is or , check the small casesSmall Answers
”is it possible to turn A into B”invariants, canonical formsReachability
output any valid object or necessary conditions, then a constructionConstructive
sum over all subarrays / pairs / subsetscontribution of each elementContribution
count objects avoiding a propertycomplement, inclusion–exclusionInclusion–Exclusion
expected valuelinearity of expectation, indicatorsProbability
nearest greater / smaller, spans, histogramsmonotonic stackMonotonic Stack
longest / shortest subarray with a monotone conditiontwo pointersTwo Pointers
range queries, no updatesprefix sums, sparse tableSparse Table
range queries with updatesFenwick or segment tree (lazy for range updates)Segment Tree
many offline range queries, hard to mergeMo’s algorithmMo
connectivity under edge additionsDSUDSU
path queries on a treeLCA, HLD, Euler tourHLD
count paths with a property in a treecentroid decomposition, small to largeCentroid
shortest path, weights 0/1 or states0-1 BFS, Dijkstra on a state graphShortest Paths
choose a subset, pairwise conflicts, bipartitematching, min vertex cover (König)Bipartite Matching
choose items with dependencies, profits and costsproject selection = min cutFlow Modeling
boolean constraints on pairs2-SAT2-SAT
xor of subsets, max xorlinear basis over GF(2)XOR Basis
count numbers in with a digit propertydigit DPDigit DP
, subsetsbitmask DP, SOS DP, meet in the middleBitmask DP
huge , linear recurrencematrix power, Berlekamp–MasseyMatrix Power DP
convex hull trick, Li ChaoCHT
”exactly items” on a convex costAliens trickAliens
, harmonic lemma / floor blocksFloor Sums
polynomial products, counting by sizeFFT / NTTFFT
impartial gameSprague–GrundySprague–Grundy
string equality checks, many substringshashing, prefix function, suffix arrayHashing

By constraints

ConstraintTypical complexityTypical tools
permutations, backtracking
bitmask DP
meet in the middle
Floyd–Warshall, interval DP
quadratic DP, bitsets for –
, sorting, segment trees, Mo
sieves, linear scans
, divisors, floor blocks, Du / min_25 sieves
matrix power, binary lifting, closed forms

Common mistakes

One line per mistake, with the fix. Full checklists: Debugging and Stress Testing, C++ for CP.

MistakeSymptomFix
int overflow in products or sumsWA on large testslong long for anything that can exceed ; 1LL * before products
product of two long long mod overflowsWA for __int128 or Montgomery
negative %negative residues((a % m) + m) % m
integer division of negatives rounds toward zerooff by one for negativesfloorDiv / ceilDiv helpers
sz(v) - 1 with unsigned size()huge loop when emptycast to int (sz macro)
not resetting globals between test casesWA on test 2clear exactly the used part, per test
memset on every testTLE with many testsreset only entries
endl in loopsTLE'\n'
recursion depth –RE (stack overflow)iterative DFS, or ulimit -s locally only
map / set where a vector sufficesTLEsort + lower_bound, arrays
unordered_map with adversarial keysTLE (anti-hash tests)splitmix64 custom hash
comparator not a strict weak order (<=)RE / WA in sortalways <
floating equalityWA on precision testsintegers, or compare with
binary search off by oneinfinite loop or wrong boundwrite the invariant: lo is always bad, hi always good
1-indexed vs 0-indexed mixingWA on borderschoose one convention per problem
forgetting , empty input, all equalWA on edge teststest the edges before submitting
graph not connected, multi-edges, self-loopsWA on hidden testshandle each explicitly
wrong modulus or forgetting a final modWAone const int MOD and a Mint type
array too small by one or by a factor of 2 (segment tree)RE / WA4n for recursive segment trees; N + 5 padding
reading the problem too fastsolving the wrong problemre-read the statement and the samples before coding
debug output left inWA / TLEprint debug to stderr with a macro

Tricks list

Small tricks that turn up everywhere, each with its use and the note that explains it.

TrickUseNote
rotate coordinates Manhattan distance becomes Chebyshev (max of two)Attacking a Problem
prefix sums / difference arrays range sums, range additions offlinePrefix Sums
prefix xorsubarray xor = xor of two prefixesPrefix Sums
sort + two pointerspairs with a sum condition in Two Pointers
coordinate compressionvalues up to into indicesSorting
contribution techniquesum over all subarrays as a sum over elementsContribution
small to largemerge sets in totalSmall to Large
sqrt split by frequency / degreeheavy and light elements handled differentlySqrt Decomposition
binary lifting-th ancestor, jumps in functional graphsLCA
reverse timedeletions become insertions (DSU)Offline Techniques
parallel binary searchmany binary searches over the same updatesParallel Binary Search
Kruskal reconstruction treequeries “max edge on the path” / thresholdsKRT
Euler tour flatteningsubtree queries become range queriesEuler Tour
submask enumeration s = (s - 1) & m over all masksSubmasks
bitset shift-orsubset sums and boolean DP in Word-Level Parallelism
random hashing of sets (xor of random 64-bit keys)compare multisets / subarrays in Randomized Algorithms
doubling the arraycyclic problems on a lineClassic Array Problems
sentinel valuesremove border checksC++ for CP
takes valuessums over divisors and quotientsFloor Sums
ternary search on a convex functionoptimum of unimodal functionsTernary Search
slope trickconvex piecewise-linear DP with heapsSlope Trick
Aliens trickremove “exactly ” by a penaltyAliens Trick
Chtholly tree (ODT)range assignment with random dataChtholly Tree
answer is smallcheck 0, 1, then the universal boundSmall Answers
meet in the middle instead of Meet in the Middle