Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
树状数组AC#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int maxn=32005; int c[maxn]={0}; struct node { int x,y; }a[maxn]; int l[15000]={0}; int p[15000]; int cmp(struct node a1,struct node a2){ if(a1.x==a2.x) return a1.y<a2.y; return a1.x<a2.x; } void Modify(int x){ for(int i=x;i<maxn;i+=(i&(-i))) c[i]++; } int Sum(int x){ int sum=0; for(int i=x;i;i-=(i&(-i))) sum+=c[i]; return sum; } int n; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y); sort(a+1,a+n+1,cmp); int k=0,px; for(int i=1;i<=n;i++){ // cout<<a[i].x<<" "<<Sum(a[i].y+1)<<endl; l[Sum(a[i].y+1)]++; Modify(a[i].y+1); } for(int i=0;i<n;i++) cout<<l[i]<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator