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

×

Getting TLE in RPLN Spoj

Problem Link - http://www.spoj.com/problems/RPLN/

Ideone Link for code - http://ideone.com/hvZSi9

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

THANKS IN ADVANCE

asked 18 Jan '16, 02:00

shubham99's gravatar image

2★shubham99
2403932
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. :)

link

answered 18 Jan '16, 16:22

mohitreddy1996's gravatar image

4★mohitreddy1996
11
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

ideone

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...

link

answered 18 Jan '16, 18:22

tanmay_sachan's gravatar image

1★tanmay_sachan
424
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: http://www.cplusplus.com/reference/ostream/ostream/flush/

(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? http://stackoverflow.com/questions/381621/using-arrays-or-stdvectors-in-c-whats-the-performance-gap

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

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×2,698
×1,901
×715

question asked: 18 Jan '16, 02:00

question was seen: 958 times

last updated: 19 Jan '16, 17:00