See the interval
1 --------------
2 -------------
3 --------
4 -----
Sort by Y first and then by X;
After sorting out the order, the question is the same as that of stars.
A traversal of the sorted array can only exist in the elements that have already been traversed because of the fact that the range of the currently traversed element strong. Therefore, we can safely sum the tree array directly.
Then, the values of the vertices that govern X in the tree array are updated backward, because these locations all have a stronger interval than the left endpoint;
Then pay attention to the processing of the same interval.
Running for MSCode. It actually feels pretty fast *-*
View code
# Include < Stdio. h >
# Include < String . H >
# Include < Algorithm >
Using Namespace STD;
# Define Maxcompute 100010
Int C [Max];
Int Val [Max];
Struct Point {
Int X, Y;
Int ID;
} A [Max];
Int CMP (point a, point B)
{
If (A. Y = B. Y)
Return A. x < B. X;
Return A. Y > B. Y;
}
Int Lowbit ( Int X)
{
Return X & ( - X );
}
Void Update ( Int X, Int D)
{
While (X <= Max)
{
C [x] + = D;
X + = Lowbit (X );
}
}
Int Sum ( Int X)
{
Int Ans = 0 ;
While (X > 0 )
{
Ans + = C [x];
X -= Lowbit (X );
}
Return Ans;
}
Int Main ()
{
Int N, I, X, Y;
While (Scanf ( " % D " , & N), n)
{
Memset (C, 0 , Sizeof (C ));
Memset (Val, 0 , Sizeof (VAL ));
For (I = 0 ; I < N; I ++ )
{
Scanf ( " % D " , & A [I]. X, & A [I]. y );
A [I]. ID = I;
A [I]. x ++ ;
}
Sort (a, + N, CMP );
Val [[ 0 ]. ID] = Sum ([ 0 ]. X );
Update ([ 0 ]. X, 1 );
For (I = 1 ; I < N; I ++ )
{
If (A [I]. x = A [I - 1 ]. X && A [I]. Y = A [I - 1 ]. Y)
{
Val [A [I]. ID] = Val [A [I - 1 ]. ID];
Update (A [I]. X, 1 );
}
Else
{
Val [A [I]. ID] = Sum (A [I]. X );
Update (A [I]. X, 1 );
}
}
For (I = 0 ; I < N; I ++ )
{
If ( ! I)
Printf ( " % D " , Val [I]);
Else Printf ( " % D " , Val [I]);
}
Printf ( " \ N " );
}
Return 0 ;
}