make a tree where each node have the following structure

1. rangeLow
2. rangeHigh
3. headCount of its complete subTree
4. boolean variable change, if true means all nodes of that subtree need to
be flipped but we are not flipping in the hope if again a flip occur we can
reset the flag and we can save some time
5.isHead

initialise range tree as for root range 0->MAX
leftSubTree 0->MAX/2 rightSubTree MAX/2+1 -> MAX
all headCount initially 0
all changes to false

as a query comes, if it matches with range of some node we can stop
propagating at that level and making change true so no need to go till leaf
nodes
new head count at that node will be (total nodes in its range - prev
headCount)


if you are still not able to get it you should read a range tree tutorial,
that will really help
On Tue, Feb 8, 2011 at 2:28 PM, Gaurav Saxena <[email protected]>wrote:

> Actually I could not figure out any good way of doing this . [?][?]
> Could you please suggest me something or give some idea .
> Thanks for helping
>
> On Tue, Feb 8, 2011 at 1:51 PM, sunny agrawal <[email protected]>wrote:
>
>> i think time complexity of the O(nlgn) for an avg case will suffice
>>
>> no it will not be inefficient if we keep sufficient information at each
>> node
>> each node will keep information of all its childs(headCount) and using
>> some optimizations such as if two flips on same range occur simultaneously,
>> then after all there will be no effect at all so there was no need of doing
>> anything.
>>
>> On Tue, Feb 8, 2011 at 1:27 PM, Gaurav Saxena <[email protected]>wrote:
>>
>>> If we make segments of the range of coins which are heads then in some
>>> case the result will become alternate which could be more inefficient. Any
>>> idea what time complexity will suffice ?
>>> Could you please elaborate your reply .
>>>
>>>
>>> On Tue, Feb 8, 2011 at 1:08 PM, sunny agrawal 
>>> <[email protected]>wrote:
>>>
>>>> i think your solution will be O(n) for each query
>>>> so it will be O(Q*N), that will surely timeout
>>>> read about Range Trees, segment trees from wiki or CLRS
>>>>
>>>> On Tue, Feb 8, 2011 at 1:01 PM, Gaurav Saxena 
>>>> <[email protected]>wrote:
>>>>
>>>>> I need help regarding the codechef flip coin problem .
>>>>> I am trying a code with O(n) time and it is giving TLE .
>>>>> Couldn't figure out a better solution.
>>>>> http://www.codechef.com/problems/FLIPCOIN/
>>>>>
>>>>> Thanks for help .
>>>>>
>>>>> --
>>>>> Thanks and Regards ,
>>>>> Gaurav Saxena
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to [email protected].
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected].
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Sunny Aggrawal
>>>> B-Tech IV year,CSI
>>>> Indian Institute Of Technology,Roorkee
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> Thanks and Regards ,
>>> Gaurav Saxena
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Sunny Aggrawal
>> B-Tech IV year,CSI
>> Indian Institute Of Technology,Roorkee
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Thanks and Regards ,
> Gaurav Saxena
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

<<344.gif>>

<<33F.gif>>

Reply via email to