标签:
5 1 1 5 1 7 1 3 3 5 5
1 2 1 1 0
Ural Collegiate Programming Contest 1999
#include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> #include<stdlib.h> #define N 32001 using namespace std; int n; int c[N]; int num[N]; int lowbit(int x) { return x&(-x); } int getsum(int x) { int s = 0; while(x>0) { s += c[x]; x -= lowbit(x); } return s; } void build(int x,int y) { while(x<=N) { c[x] += y; x += lowbit(x); } } int main() { while(scanf("%d",&n)!=EOF) { memset(num,0,sizeof(num)); memset(c,0,sizeof(c)); int x,y; for(int i=0; i<n; i++) { scanf("%d%d",&x,&y); num[getsum(x+1)]++ ; build(x+1,1); } for(int i=0; i<n; i++) { printf("%d\n",num[i]); } } return 0; }
版权声明:本文为博主原创文章,如有特殊需要请与博主联系 QQ : 793977586。
标签:
原文地址:http://blog.csdn.net/yeguxin/article/details/47747407