Codeforces и Polygon могут быть недоступны в период с 6 декабря, 22:00 (МСК) по 7 декабря, 00:00 (МСК) в связи с проведением технических работ. ×

Блог пользователя ShardsOfNarsil

Автор ShardsOfNarsil, 24 часа назад, По-английски

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?

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
23 часа назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

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.

  • »
    »
    23 часа назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
23 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

These templates will help you not to write long commands

»
20 часов назад, # |
Rev. 3   Проголосовать: нравится +7 Проголосовать: не нравится

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)

»
19 часов назад, # |
  Проголосовать: нравится +20 Проголосовать: не нравится

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.

  • »
    »
    14 часов назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

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

»
13 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    10 часов назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    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.

»
11 часов назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

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
}
»
8 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I don't use templates very often tho :) They are a bit annoying for me to have to remember all the settings and I prefer to see the regular code.

»
6 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

i don't think they make much difference i have seen newbies with a long list of utils and macros also people over 2400 just using pushback and some commonly used ones it totally depends your feel, some people find it time consuming to implement themselves others forget about what was it defined for so choose for yourself

»
3 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I use defines just because it is more comfortable for me, for e.g., to write all(vec) instead of vec.begin(), vec.end(),but I do not think that I make a huge difference in time using defines)

But templates for algorithms or data structures really increase ur speed. Firstly, u can spend 1 minute to copy default seg tree instead of 5 mins to write it. Secondly, u can be sure that already written code works right and u do not need to find mistakes in it