POJ 2352 stars tree-like array

Source: Internet
Author: User

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

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.