Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

.o.'s blog

By .o., history, 3 years ago, In English,

Hi.

Today I got WA on F just because I forgot to use long long instead of int on 1 line of code..

Although I used a bunch of compile options from this blog post, it couldn't catch that bug. (I removed some of the options because it didn't work on my computer, maybe that could be the reason.)

Recently my rating has dropped a lot because I had silly mistakes for at least one problem, so I am finding a way how to avoid mistakes.

And I thought of my failed hack of this solution. I got -50 points just because I couldn't find the "#define int long long" line and provided a huge input for the problem.

At first I was quite upset and thought they did such thing to deceive hackers, but nowadays I'm thinking that's quite a great way to avoid mistakes. So I decided to use #define int long long for the next rated round. But maybe there are some defects on this trick I couldn't find, so I would like to know some disadvantages caused by #define int long long. Could you please help me?

Thanks in advance. :D

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

»
3 years ago, # |
Rev. 4   Vote: I like it +21 Vote: I do not like it

You should be able to decide when you need 64-bit integers!

There is one main disadvantage: every computation will be done in 64 bits and it can become expensive rapidly (think of basic computations inside a loop). Run the code below with all ints and all long longs and see what you get in each case.

#include <iostream>
using namespace std;

int main()
{   
   int M = 0;
   constexpr int N = 2000000000;
   
   for (int x = 0; x < N; x++)
        M = max(M, x);
        
    cout << M << endl;
    
    return 0;
}
»
3 years ago, # |
  Vote: I like it +9 Vote: I do not like it

You can run out of memory in problems with tighter memlimit.

»
3 years ago, # |
  Vote: I like it +25 Vote: I do not like it

I've been using the #define for a quite a while and I've only noticed 2 small disadvantages.
1. Memory usage. This can be fixed by using int32_t for segment trees/large arrays.
2. Speed. There is usually a small difference but it is noticeable when using algorithms like MO's / sqrt decomposition.

»
3 years ago, # |
  Vote: I like it +79 Vote: I do not like it

Although we are in 2K17, CF uses 32-bit machines, so long long is significantly slower than int.

  • »
    »
    11 months ago, # ^ |
      Vote: I like it +26 Vote: I do not like it

    That's not the only reason. If you use long long everywhere but others can use int to solve the problem, your working set size would be twice. That reduces the efficiency of cache. This is lethal sometimes. We've observed significant performance issues with some programs using long long everywhere, on the 64-bit judge machine of our university.

»
3 years ago, # |
  Vote: I like it +5 Vote: I do not like it

As mentioned above long long is significantly slower than int. And using #define int long long you make a lot of useless changes from int to long long. Here is an example for that — I failed Div.1 C in round 381 just because of this (it TLE).

  • 22444469 — TLE with #define int long long

  • 22450108 — AC with canged int to int64_t

»
11 months ago, # |
Rev. 3   Vote: I like it -54 Vote: I do not like it

The comment is hidden because of too negative feedback, click here to view it

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it -43 Vote: I do not like it

    why did he get downvoted? what is the comment?

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it -12 Vote: I do not like it

      you can click the arrow next to "Rev. 3" on the right corner of the comment to see previous changes