Question Link
Description
Astequalmers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. let the level of a star be an amount of the stars that are not higher and not to the right of the given
Star. astpolicmers want to know the distribution of the levels of the stars ................... Tree array, simple question, I just started learning a, don't talk much, directly paste code.
# Include <stdio. h> # include <string. h> int A [32002]; int level [15002]; int lowbit (int x) {return X & (-x);} void insert (int x) {While (x <32002) {A [x] ++; x + = lowbit (x) ;}} int sum (int x) {int S = 0; while (x) {S + = A [X]; X-= lowbit (x);} return s;} int main () {int N, I, X, Y; scanf ("% d", & N); memset (A, 0, sizeof (level); memset (Level, 0, sizeof (level )); for (I = 0; I <n; I ++) {scanf ("% d", & X, & Y); X ++; level [sum (x)] ++; insert (x) ;}for (I = 0; I <n; I ++) printf ("% d \ n ", level [I]); Return 0 ;}