POJ2352 tree Array

Source: Internet
Author: User

Individual NO. 1

An error occurred while understanding the question at the beginning.

A star has N stars at the bottom left, and its level is N.

At first, we understood that both X and Y must be less than the two coordinates. Then, we can see from the example that we only need the lower left corner. The X and Y coordinates must be less than or equal to, but not the stars themselves.

 

# Include <iostream> # include <stdio. h> # include <string. h> using namespace std; int lowbit (int x) {return x &-x;} int c [32005]; int x [32005]; int n; int ans [32005]; int visit [32005]; int a [32005]; void add (int x, int y) // all subsequent values are worth updating, excluding itself {while (x <= 32005) {c [x] + = y; x + = lowbit (x) ;}} int sum (int x) {int ret = 0; while (x> 0) {ret + = c [x]; x-= lowbit (x);} return ret;} int main () {while (scanf ("% d", & n )! = EOF) {memset (c, 0, sizeof (c); memset (x, 0, sizeof (x); memset (ans, 0, sizeof (ans )); int x, y; for (int I = 1; I <= n; I ++) {scanf ("% d", & a [I], & y); if (visit [a [I] + 1] = 0) {add (a [I] + 2, 1 ); visit [a [I] + 1] = 1;} else add (a [I] + 1, 1 ); // c [I] indicates the number of ans [sum (a [I] + 1)] ++;} for (int I = 0; I <n; I ++) printf ("% d \ n", ans [I]);} return 0 ;}# include <iostream >#include <stdio. h> # include <string. h> using namespace std; int lowbit (int X) {return x &-x;} int c [32005]; int x [32005]; int n; int ans [32005]; int visit [32005]; int a [32005]; void add (int x, int y) // all subsequent values are worth updating, excluding itself {while (x <= 32005) {c [x] + = y; x + = lowbit (x) ;}} int sum (int x) {int ret = 0; while (x> 0) {ret + = c [x]; x-= lowbit (x);} return ret;} int main () {while (scanf ("% d", & n )! = EOF) {memset (c, 0, sizeof (c); memset (x, 0, sizeof (x); memset (ans, 0, sizeof (ans )); int x, y; for (int I = 1; I <= n; I ++) {scanf ("% d", & a [I], & y); if (visit [a [I] + 1] = 0) {add (a [I] + 2, 1 ); visit [a [I] + 1] = 1;} else add (a [I] + 1, 1 ); // c [I] indicates the number of ans [sum (a [I] + 1)] ++;} for (int I = 0; I <n; I ++) printf ("% d \ n", ans [I]);} return 0 ;}

 

Related Article

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.