deam0n's blog

By deam0n, 11 years ago, In English

I'm trying to solve a RMQ problem at lightoj using Segment Tree , but it always gives me TLE. Can anybody help in pointing out my mistake ?

Problem link : http://www.lightoj.com/volume_showproblem.php?problem=1082

Code link : http://pastebin.com/UqaumDKG

Tags rmq
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I had the same problem many times in SPOJ. First, try replacing 'endl' by '\n'. If still TLE, try using stdio.h instead of iostream.

  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks ,replacing it with stdio.h get me accepted.

    • »
      »
      »
      11 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Did you notice the following:

      Note
      Dataset is huge. Use faster I/O methods.
      

      In such cases, for C++, <cstdio> is required instead of <iostream>.