damn_me's blog

By damn_me, 10 years ago, In English

Why is the following code giving TLE for the PROBLEM

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

| Write comment?
»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Check out your link to the problem. "The requested URL was not found on this server.".

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

You need faster IO. cin and cout are too slow ( even using ios::sync_with_stdio(false) ) .

Even scanf and printf are slow for this problem.I used them and got TLE. After that I used getchar_unlocked() and got AC .

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

    scanf() printf() is enough. I got AC using scanf() and printf().

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

    my code having faster i/o function.

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      Faster input maybe, but not output. Don't use endl, use '\n' instead. Even better if you replace the whole thing with printf("%d\n", query(1,0,n-1,x,y));

      Also you could try replacing every 2 * node with node << 1 and every 2 * node + 1 with (node << 1) | 1, maybe it will help.