Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

vaishali614's blog

By vaishali614, history, 4 weeks ago, In English,

Hello! I tried to solve this problem on SPOJ. Here is my solution. Its showing TLE. Can anyone please help solving this? Thanks

 
 
 
 
  • Vote: I like it
  • -5
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

log2() returns a double. Try __lg().

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    but i'm getting TLE, not WA.

    • »
      »
      »
      4 weeks ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Yeah, you could be sitting in that while loop on line 49 infinitely if log2() gets rounded the wrong way. In any case, loops like that are scary, and I would certainly try to change it to a for loop if possible, especially if I was getting TLE. Take a look at how the loop is done here.

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks. But that wasn't an issue i think. Anyway, I'll take care of this thing from next time :)

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

It is multiple testcases, you should clear() your tree before each one. Or better, do not use global variables.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it
d -= (1 << i);

try to change this to 1LL<<i wheerever you have used this