Bouhmid's blog

By Bouhmid, history, 6 years ago, In English

36704837 : In this code when l=10000000000 and r=2000000000 I have a succes submission, but when I remove the comment from the line: " cout<<i<<" "<<j<<" "; " it becomes time limit exceeded .. Why ?

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

»
6 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Perhaps you will want to replace (1 << i) by (1LL << i), and the same with j.
See, for example, here for why the former is undefined behavior.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yes, I had an accepted with using 1LL .. But the question is why when I use i or j it becames time limit exceeded? Is the Compiler too smart? When loops are useless the compiler threw them out ? and when I used i and j it becames TLE ?

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      Sure, as per standard, having an infinite loop without side effects is undefined behavior. See, for example, here and there.

      So, for unused variables, the whole loop which affects only that variable could be optimized away. And indeed it is.


      That said, the question looks interesting, but answering it does not help much. A better question would be: how to write code to minimize the chance of introducing undefined behavior, like this time? If you also ask yourself that, here is further reading on Codeforces that may help.