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 |
树状数组不解释,注意0&0会死循环#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<set> #include<vector> using namespace std; const int maxn=3e4+2010; int a[15000+10],c[maxn]; int lowbit(int x) { return x&(-x); } void update(int x) { while(x<=maxn) { c[x]+=1; x+=lowbit(x); } } int sum(int x) { int sum1=0; while(x>0) { sum1+=c[x]; x-=lowbit(x); } return sum1; } int main() { int n; while(~scanf("%d",&n)) { memset(c,0,sizeof(c)); memset(a,0,sizeof(a)); for(int i=1;i<=n;i++) { int x,y; scanf("%d %d",&x,&y); int num=sum(x+1); a[num+1]++; update(x+1); } for(int i=1;i<=n;i++) printf("%d\n",a[i]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator