📊
Informatics Notes
  • About
  • About Programming Contests
  • Terminal Setup
  • Editor Setup
  • Debugging
  • Syntax and Templates
    • Scopes 101
    • Quickest IO Library
    • Writing Generic Code (Advanced Bronze)
    • Making a Contest Template
  • USACO Specific
    • Strategy for USACO Bronze
    • Preparing for Contests
    • USACO Division Ladders
    • Division Ladders Answers
  • Binary Lifting (Gold)
    • Binary Lifting (Gold) Intro
    • Binary Lifting (Gold) Part 1
    • Binary Lifting (Gold) Part 2
    • Binary Lifting (Gold) Part 3
  • Graphs (Silver)
  • Sweep Line
    • Sweep Line (Silver-Gold) Intro
    • Sweep Line (Silver-Gold) Part 1
  • Misc Tricks
    • Some C++ Contest Tricks I Wish I Were Told
    • Bitmasking: Generating Subsets Iteratively
    • Difference Arrays (Silver)
    • "Unusing" Identifiers
Powered by GitBook
On this page

Was this helpful?

  1. Misc Tricks

Some C++ Contest Tricks I Wish I Were Told

PreviousMisc TricksNextBitmasking: Generating Subsets Iteratively

Last updated 3 years ago

Was this helpful?

  1. #include <bits/stdc++.h> is a much better option over listing the libraries you use manually, especially now that prewritten code is banned. Use it! If your compilation complains such a file does not exist, there are numerous methods out there to add this file. Just use Google.

  2. Use GCC over Clang! Clang often complains about C++ versions and spacing. If you use GCC, use for (basically sets with indices on them!) and ! This also opens the door to the possibility of among many other data structures.

  3. 0/1 knapsack tricks for dynamic programming: For starters, you can space optimize the standard 0/1 knapsack with a . You can use the exact same code for your unbounded knapsack and 0/1 knapsack!

  4. Ever wish you could pass arrays into functions like you can vectors? Well, you can with std::arrayThis is a better alternative to tuples (and in some cases even pairs).

  5. For prefix sums, you can use partial_sum(a,a+n,b) to prefix sum the first n elements of an array a and put this result into b. To make an array its own prefix sum, you can just do partial_sum(a,a+n,a). In fact, there's also a function to create difference arrays (inverse prefix sums). You can do adjacent_difference(a,a+n,b) and adjacent_difference(a,a+n,a) respectively.

  6. Other valuable articles:

policy based data structures
order statistics trees
faster hash tables
iterative sparse segment trees
sliding window technique
Just loop backwards.
https://www.geeksforgeeks.org/c-tricks-competitive-programming-c-11/
https://codeforces.com/blog/entry/15643
https://medium.com/@nilotpalmrinal9797/useful-c-tricks-8f251276a53d
https://www.tutorialspoint.com/some-useful-cplusplus-tricks-for-beginners-in-competitive-programming