Poj 2352 stars tree Array

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.