competitive-programming
Competitive Programming
Competitive programming is solving algorithm puzzles against a clock: a judge runs your code on hidden tests and it has to be right and fast. Salman spent about eight months on it full time, starting with a university course. This is that work cleaned up: 361 C++ solutions filed by topic, every one of them compiling, and the data-structure solutions checked against a slow, obviously correct version on thousands of random inputs.
Solo work by Salman Adnan. Course solutions are from CS 334 at Habib University.
Overview
361 C++ solutions to problems from Codeforces, CSES, AtCoder and CS Academy. Most are practice worked by topic: two pointers, bitmasks, prefix sums, number theory, graphs, dynamic programming and range queries. The rest come from 7 Codeforces rounds, 5 AtCoder contests, and the class contests, labs and problem sets of CS 334 at Habib University. Most of them, 267 of the 361, are written inside one of two sizes of the same contest template; the full one is in the repository too. Another 30 files, written by other people and kept for study, sit apart in their own labelled folder and are not counted.
Key features
- The CSES Range Queries section solved with the structures it is there to teach: a Fenwick tree, a segment tree, a lazy segment tree for range add, one carrying both an add tag and an assign tag, and one carrying an arithmetic progression.
- Hotel Queries answered by walking down a max segment tree to the leftmost hotel with enough rooms, in O(log n) rather than binary searching over range queries.
- A stress harness that feeds each range-query solution random inputs and compares every answer to a brute-force loop. The seed is fixed, so a failure reproduces exactly.
- A regression script for the bugs a full review turned up: each fixed solution is checked against a brute force written from its problem statement, with sanitizers on.
- A build script that compiles every file with the flags a judge uses and reports anything that fails.
Results
Verified on 2026-10-26 in a clean gcc:13 container: every file in the repository, the template included, compiles with g++ 13 at -std=gnu++17 -O2, all eight range-query solutions agree with brute force on 1,000 random cases each, and every solution fixed after a line-by-line review passes its own brute-force test under AddressSanitizer. To prove the checks can fail, the minimum query was deliberately broken and it failed on the first case, and the old versions of the fixed solutions fail the same tests.