ShardsOfNarsil's blog

By ShardsOfNarsil, 14 hours ago, In English

Does having templates like this:


#define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define eb emplace_back #define F first #define S second #define sz(x) int((x).size()) #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = (b)-1; i >= (a); --i)

useful in anyway or is it just preference?

  • Vote: I like it
  • +7
  • Vote: I do not like it

»
14 hours ago, # |
  Vote: I like it +3 Vote: I do not like it

It is useful because it allows you to write code faster in theory, however I doubt its effect on your performance is significant in any way.

  • »
    »
    13 hours ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    yeah thats what i was thinking. I personally feel like your performance dont depend much on your typing speed especially for harder questions where a lot of thinking is involved.

»
14 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

These templates will help you not to write long commands

»
10 hours ago, # |
Rev. 3   Vote: I like it +8 Vote: I do not like it

Templates could save up to 20 minutes of coding time for me every contest, which doesn't give significant performance rise. So for me it provides better QoL but not rating boost.

Maybe another point is that templates make your code cleaner (e.g. modular integer classes, rep(i,x,y) macros)

  • »
    »
    9 hours ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    I don't think macros are that great. It can be confusing for others to look at your code

»
10 hours ago, # |
  Vote: I like it +16 Vote: I do not like it

Those are mostly preference and convenience, not saving that much time at all. However, some bigger templates of things like segment tree can save lots of time rather than having to code out all the functions. These small things you listed are just preferences, with possibly a few seconds total max saved.

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    yeah copy pasting well know data structures and algos are obviously time savers. I was mostly talking about these kind of short cuts.

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

when they are useful they are very nice, its just not that often, but id rather avoid the annoying feeling of coding something complicated that i know well during contest

  • »
    »
    18 minutes ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    I am talking about macros not standard data structures like trie or segment tree. Obviously no one is gonna code up a segment tree or sparse table during contest.

»
81 minute(s) ago, # |
  Vote: I like it +1 Vote: I do not like it

I would say the main benefit of these (for me) is that it prevents me from doing the dreaded

for (int j = 0; j < n; i++) {
    // code
}