|
|
back to boardI counldnt solve this problem easy and got AC only using AVL-tree... Can you explain me the easiest solution? 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 Re: I counldnt solve this problem easy and got AC only using AVL-tree... Can you explain me the easiest solution? 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. ;-) |
|
|