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

Show all messages Hide all messages

int main()
{
    int N = 0;
    scanf("%d",&N);
    rangs = new int[N];
    Star *stars = new Star[N];

    for(int i = 0; i < N; i++) {
        scanf("%d %d", &stars[i].x, &stars[i].y);
    }

    qsort(stars, N, sizeof(Star), StarCompare);

    AVLTreeNode *root = new AVLTreeNode();

    for(int i = 0; i < N; i++) {
        rangs[i] = 0;
    }

    for(int i = 0; i < N; i++) {
        AVLTreeNode::Insert(root, stars[i].y, 0);
    }

    for(int i = 0; i < N; i++) {
        printf("%d\n", rangs[i]);
    }

    return 0;
}

Edited by author 05.02.2011 00:23
Two advices:
1) There's no need in Y-coordinates since points are sorted in input. Ignore them.
2) You should find a way to answer quickly on queries "how many numbers are lesser than given one".

P.S. I used Binary Indexed Tree (Fenwick's Tree) for this problem and got a code of the same length as your pseudocode. ;-)