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

What is wrong with my code?
Posted by Alexander Bovkun 7 Mar 2005 23:37
I used RSQ(Range Sum Query) to solve this problem, but got Wrong Answer. Everything seems to be OK and I don't know where is a mistake. Here is my code:

{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R+,S+,T-,V+,X+}
{$M 16384,0,655360}
Program Stars;
Var N:Integer;
    RSQ:Array[1..32000] Of Integer;
    Levels:Array[0..14999] Of Integer;
    I,J,K,X,Y:LongInt;
Begin
  ReadLn(N);
  For I:=1 To N Do Begin
    ReadLn(X,Y);

    J:=X;K:=0;
    While J>=1 Do Begin
      K:=K+RSQ[J];
      J:=J-(J And ((J-1) Xor J));
    End;
    Inc(Levels[K]);

    While X<=32000 Do Begin
      Inc(RSQ[X]);
      X:=X+(X And ((X-1) Xor X));
    End;
  End;
  For I:=0 To N-1 Do WriteLn(Levels[I]);
End.
I have made a little error...
Posted by Alexander Bovkun 13 Mar 2005 15:06
If you put the line "Inc(X);" after "ReadLn(X,Y)" and change all 32000 on 32001 it will be AC. Complexity of my algorithm is N*Log(M) where N is number of stars and M is maximal possible value of axis of the star. It works only 0.031 sec!

Edited by author 13.03.2005 15:07
Re: I have made a little error...
Posted by Olzhas2dy 13 Jun 2007 17:36
Where can I found out more about RSQ?