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


need help in pointing out my mistake>

asked 09 Dec '17, 16:40

viralivora's gravatar image

accept rate: 14%

Its simple. Use double not float because you need precision for values as large as ${2}*{10}^{8}$.

See this TC-

100000000 100000000 100000000 100000000 99999999
2 4
Your Output
Correct Output

Determining what data type to use is the most fundamental concept which requires 100% accuracy. Be careful next time.

Also, next time, please give 2 minutes into indenting your code or adding proper comments. Its really painful for eyes to see an un-indented and uncommented code. Please think of the person going through your code to help you.


answered 09 Dec '17, 19:25

vijju123's gravatar image

4★vijju123 ♦♦
accept rate: 18%

edited 09 Dec '17, 19:26

thanks a lot!! And I definitely will try to indend my code from next time..

(09 Dec '17, 20:04) viralivora3★

Thank you dear :)

(09 Dec '17, 21:51) vijju123 ♦♦4★

It is a basic segment tree problem with an insight.

View Content

answered 09 Dec '17, 16:58

taran_1407's gravatar image

accept rate: 22%

edited 09 Dec '17, 17:02

this is exactly what I have done. it would be helpful if you could point out the mistake in my code

(09 Dec '17, 17:01) viralivora3★

i guess you should use ceil function for ceil( (max(L,R) - min(L,R))/2)

(09 Dec '17, 17:04) taran_14075★

Also, refer this implementation of Segment tree for min-max queries

(09 Dec '17, 17:06) taran_14075★

but i did max((max(l,r)+min(l,r))/2,min(l,r)+max( max(0, L-1), max(R+1, N-1))) which is basically the same thing and hence does not require ceil function

(09 Dec '17, 17:21) viralivora3★


I'm solving it myself..

(09 Dec '17, 17:27) taran_14075★

it would be nice if u could point out error in my code,instead of solving it your self:)

(09 Dec '17, 17:48) viralivora3★

Your segment tree is working fine..

(09 Dec '17, 17:54) taran_14075★

Can't figure out what's wrong with your code... :(

My code with same approach gives AC

(09 Dec '17, 18:07) taran_14075★

thanks for your help.. found the solution to my problem

(09 Dec '17, 20:07) viralivora3★

No problem. Although @vijju123 is the one to be thanked.

(09 Dec '17, 22:07) taran_14075★
showing 5 of 10 show all
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: 09 Dec '17, 16:40

question was seen: 316 times

last updated: 09 Dec '17, 22:07