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 | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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.