Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

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

Автор Bouhmid, история, 6 лет назад, По-английски

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 ?

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

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

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

    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 лет назад, # ^ |
        Проголосовать: нравится +6 Проголосовать: не нравится

      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.