wirserd's blog

By wirserd, history, 39 minutes ago, In English

Hi everyone,

I'm new to competitive programming and I use C++. I've solved about 40 problems on Codeforces and CSES.

I saw many people use templates like this:

#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

What I understand so far

Macros just replace text before compilation, so they save typing. For example, sort(all(v)) instead of sort(v.begin(), v.end()).

What confuses me

  1. I read that this macro is dangerous: cpp #define sq(x) x * x sq(a + b) becomes a + b * a + b, which is wrong. I fixed it with ((x) * (x)), but I'm not sure when this kind of bug can appear in a real contest.

  2. I heard that using ll = long long; is better than #define ll long long. Is there a real difference in practice, or is it only about style?

My question: Do you recommend that beginners use macros, or only using ll = long long;? Which macros do you actually use?

Thanks for reading, and sorry for any English mistakes!

Full text and comments »

  • Vote: I like it
  • -4
  • Vote: I do not like it