Competitive programming

Stage 1 · Lesson 6 of 8

STL algorithms you will use weekly

C++ for contests

The standard library already has functions for most small jobs. unique after sort removes duplicates. accumulate sums a range, max_element finds the largest value, reverse flips a range and iota fills 0, 1, 2 and so on.

next_permutation walks through every ordering, which is how you small inputs. Each one replaces a loop you could get wrong at minute 90 of a contest, and each is tested and fast. Read about them on cppreference, a reference site for C++, and use them until they are automatic.

Common trapcalling accumulate with 0 as the starting value, which sums in int and overflows on large inputs, where 0LL sums in long long.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CourseFree
    LearnCpp.com

    LearnCpp.com · Beginner

    Free and thorough: read the chapters on vectors, references, lambdas and the standard library if C++ is new to you

  • BookFree
    Competitive Programmer's Handbook

    Antti Laaksonen · Beginner

    Chapter 1 covers C++ for contests, input and output and working with numbers; Chapter 2 covers complexity

Practise

  • Start with the Introductory Problems section: short tasks that exercise loops, strings and the STL

  • Filter the problem set to rating 800 and solve a few each day to get used to contest input and output

Keep handy

  • Keep it open for exact signatures and complexities of vector, set, map, sort and lower_bound

Also worth your time

Mark this stage as not done?