The topic was not read at first, thought to be a two-dimensional tree array to find the upper corner matrix and.
In fact, there is no two-dimensional, because the data is ordered, each time the request is the X-direction of the comparison. But the mistake also wrote a discrete code.
WA:
#include <cstdio> #include <string> #include <iostream> #include <map> #include <iterator >using namespace std; #define N 15000int c[n][n],n,mm; int D[n];int a[n],b[n];struct M{bool operator () (const int &a,const int &b) {return a<b;}}; map<int,int,m> mp;int lowbit (int x) {return-x&x;} void update (int r,int l,int num) {int i,j;for (i=r;i<=mm;i+=lowbit (i)) for (J=l;j<=mm;j+=lowbit (j)) C[i][j]+=num;} int sum (int r,int l) {int ans=0;int i,j;for (i=r;i>0;i-=lowbit (i)) for (J=l;j>0;j-=lowbit (j)) Ans+=c[i][j];return Ans;} int main () {int i,j,k;while (~scanf ("%d", &n)) {memset (c,0,sizeof (c)); Memset (d,0,sizeof (d)); for (i=1;i<=n;i++) {scanf ("%d%d", a+i,b+i); a[i]++;b[i]++;mp[a[i]]++;mp[b[i]]++;} Map<int,int,m>::iterator It=mp.begin (); for (I=1;it!=mp.end (); it++,i++) It->second=i;mm=i-1;for (i=1;i< =n;i++) {a[i]=mp[a[i]];b[i]=mp[b[i]];update (b[i],a[i],1);} for (i=1;i<=n;i++) {k=sum (b[i],a[i]);d [k-1]++;} for (i=0;i<n;i++) printf ("%d\n", D[i]);} return 0;}
AC:
#include <cstdio> #include <string> #include <iostream> #include <map> #include <iterator >using namespace std; #define N 150001int c[n],n,mm; int d[n];int a[n];int lowbit (int x) {return-x&x;} void update (int r,int num) {int i;for (i=r;i<=n;i+=lowbit (i)) c[i]+=num;} int sum (int r) {int Ans=0;int i;for (i=r;i>0;i-=lowbit (i)) ans+=c[i];return ans; int main () {int i,j,k;while (~scanf ("%d", &n)) {memset (c,0,sizeof (c)); Memset (d,0,sizeof (d)); for (i=1;i<=n;i++) {scanf ("%d%d", A+i,&j), A[i]++;update (a[i],1);d [sum (a[i]) -1]++;} for (i=0;i<n;i++) printf ("%d\n", D[i]);} return 0;}
POJ 2352 stars tree-like array