You are not logged in. Please login at to post your questions!


Getting TLE in RPLN Spoj

Problem Link -

Ideone Link for code -

I have used Segment tree method to solve this.Please help me in figuring out what's wrong with this code.


asked 18 Jan '16, 02:00

shubham99's gravatar image

accept rate: 5%

edited 18 Jan '16, 04:26

Instead of using cout and cin use printf() and scanf().

You dont have to initialise the tree with zero for every test case.

I think this should do. :)


answered 18 Jan '16, 16:22

mohitreddy1996's gravatar image

accept rate: 0%

done , still getting TLE. Thanks for helping though :)

(18 Jan '16, 16:30) shubham992★

still need help? Your code get ac when submitted by removing all the "endl"s


in general, avoid using endls, instead use '\n'. but if you still want your endls, just include this line on top of your code->

" #define endl '\n' "

if this helped, it would be great if you could upvote this answer...


answered 18 Jan '16, 18:22

tanmay_sachan's gravatar image

accept rate: 9%

edited 18 Jan '16, 18:24

It helped me get the AC thanks for that.

But , I was actually looking for corrections in approach.Anyways , thanks for the help though.

You will get an upvote for this buddy :)

(18 Jan '16, 20:47) shubham992★

@shubham99, the reason is using endl flushes the output stream after printing new line. Hence its slower where's otherwise all data is stored in a buffer and whole buffer is printed at once. Link:

(18 Jan '16, 21:07) vsp46★

Thanks @vsp4 , I have seen that link after looking at that answer although thanks for pointing it out. Actually , I am looking for the optimizations to make my program faster if possible by some small corrections missed by me.

(18 Jan '16, 21:15) shubham992★

i don't think that you would be able to make this Segtree any faster. All the operations are perfect. Also, why not use vectors?

(19 Jan '16, 16:59) tanmay_sachan1★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 18 Jan '16, 02:00

question was seen: 958 times

last updated: 19 Jan '16, 17:00