ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1028. Stars

How to solve so fast? Help me, please!
Posted by Aleksei Zobnin 17 Jan 2002 16:26
A hint for you.(+)
Posted by shitty.Mishka 17 Jan 2002 18:12
There are a lot of problems where the same idea can be used.

Try to think of such a problem first:
You have a string of n zeroes.
Then there will be a series of either requests or data changings
(they may follow in any order).
On a request you have to output the first non-zero element of the
string (or say that all the elements are zeroes).
On a data changing you have to increase or decrease the value of one
element.

The obvious algorythm will take you O(1) at each data changing and
O(n) at each request. Try to think of an algorythm that will take
O(Sqrt(n)) at each request and at each data changing.

I'm sure that if you solve this problem, you'll be able to solve the
stars problem as well.

Good luck!
Thank you! I've got AC!
Posted by Aleksei Zobnin 17 Jan 2002 22:03
That's great!
Re: A hint for you.(+)
Posted by Christopher Moh 18 Jan 2002 20:13
> There are a lot of problems where the same idea can be used.
>
> Try to think of such a problem first:
> You have a string of n zeroes.
> Then there will be a series of either requests or data changings
> (they may follow in any order).
> On a request you have to output the first non-zero element of the
> string (or say that all the elements are zeroes).
> On a data changing you have to increase or decrease the value of
one
> element.
>
> The obvious algorythm will take you O(1) at each data changing and
> O(n) at each request. Try to think of an algorythm that will take
> O(Sqrt(n)) at each request and at each data changing.
>

Hi,

are you suggesting an O(n sqrt(n)) solution for stars?  Well, I think
that O(n log n) suffices, but O(n sqrt(n)) should be able to beat the
time limit.

As for that question, I think I can get O((log n)^2) request and O
(log n) update.  I am sure other better algorists can beat this
complexity however.

Thanks.
O(1) for Change and O(lg(n)) for Request...
Posted by Locomotive 17 Feb 2003 10:17
But how i solve stars with it?
Re: O(1) for Change and O(lg(n)) for Request...
Posted by Sergei Pupyrev (USU) 3 Mar 2003 19:44
Can you tell me how to do it?
mailto: pserega@r66.ru
Thanks.