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 ?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Name |
---|
Perhaps you will want to replace
(1 << i)
by(1LL << i)
, and the same withj
.See, for example, here for why the former is undefined behavior.
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 ?
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.