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 | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
2 | maomao90 | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | 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.