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)