wirserd's blog

By wirserd, history, 10 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!

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
2 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

well in some contests u wouldnt get to use macros, like olys

so it will be better to practice without macros., and idont think that using macros will give u any benefit in usual contests, macros only matter when u r in blitz contests