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

×

need help in pointing out my mistake>

asked 09 Dec '17, 16:40

viralivora's gravatar image

4★viralivora
1838
accept rate: 14%


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

See this TC-

Input
5
100000000 100000000 100000000 100000000 99999999
1
2 4
Your Output
200000000.0
Correct Output
199999999.0

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.

link

answered 09 Dec '17, 19:25

vijju123's gravatar image

6★vijju123 ♦
14.5k11854
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) viralivora4★

Thank you dear :)

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

It is a basic segment tree problem with an insight.

View Content
link

answered 09 Dec '17, 16:58

taran_1407's gravatar image

6★taran_1407
3.6k1348
accept rate: 24%

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) viralivora4★

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

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

http://www.geeksforgeeks.org/min-max-range-queries-array/

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

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

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) viralivora4★

Wait..

I'm solving it myself..

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

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

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

Your segment tree is working fine..

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

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

My code with same approach gives AC

https://www.codechef.com/viewsolution/16521589

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

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

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

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

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

×470
×290
×17

question asked: 09 Dec '17, 16:40

question was seen: 295 times

last updated: 09 Dec '17, 22:07