看完题解自己敲了一遍 还需要加深理解吧
#include<cstdio> #include<cstring> #include<iostream> using namespace std; int c[50000],num[50000]; int N=32100; int lowbit(int x) { return x&(-x); } int sum(int x) { int ret=0; while(x>0) { ret+=c[x]; x-=lowbit(x); } return ret; } void add(int x,int d) { while(x<=N) { c[x]+=d; x+=lowbit(x); } } int main() { int t; int i,j; while(cin>>t) { memset(c,0,sizeof(c)); memset(num,0,sizeof(num)); for(i=0;i<t;i++) { int x,y; scanf("%d%d",&x,&y); num[sum(x+1)]++; add(x+1,1); } for(i=0;i<t;i++) { printf("%d\n",num[i]); } } return 0; }
时间: 2024-10-26 13:43:28