HDU 1556 Color The ball (tree-shaped array) (pits)

Source: Internet
Author: User

Title Address: HDU 1556

Because listen to other people say tree array can do the line of tree can be, so also has not learned, but now encountered a lot of card segment tree ... On my knees. So learn to fill pits.

This should be the entry question for the tree array. Not much to say.

The code is as follows:

#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h>using namespace std; #define LL __int64int a[110000], n;int lowbit (int x) {return x& (-X);}                void Update (int x, int p) {while (x>0) {a[x]+=p;        X-=lowbit (x);        }}int Sum (int x) {int s=0;                while (x<=n) {s+=a[x];        X+=lowbit (x); } return s;}        int main () {int I, J, L, R;                while (scanf ("%d", &n)!=eof&&n) {memset (a,0,sizeof (a));                        for (i=0;i<n;i++) {scanf ("%d%d", &l,&r);                        Update (r,1);                Update (l-1,-1);                        } for (i=1;i<=n;i++) {printf ("%d", Sum (i));                              if (i!=n)  printf ("");        } puts (""); } return 0;}


HDU 1556 Color The ball (tree-shaped array) (pits)

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.