标签:des style blog http color os strong io
Description
Input
Output
Sample Input
5 1 1 5 1 7 1 3 3 5 5
Sample Output
1 2 1 1 0
最基础的树状数组
1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include<algorithm> 8 #include<cstring> 9 #include<stdlib.h> 10 #include<string> 11 #include<cmath> 12 using namespace std; 13 #define pb push_back 14 int n,p[32100],num[32100]; 15 void update(int pos){ 16 while(pos<=32001){ 17 p[pos]+=1; 18 pos+=pos&(-pos); 19 } 20 } 21 int getnum(int pos){ 22 int sum=0; 23 while(pos>=1){ 24 sum+=p[pos]; 25 pos-=pos&(-pos); 26 } 27 return sum; 28 } 29 int main(){ 30 while(cin>>n){ 31 memset(p,0,sizeof(p)); 32 memset(num,0,sizeof(num)); 33 for(int i=1;i<=n;i++){ 34 int x,y;scanf("%d%d",&x,&y); 35 x++; 36 num[getnum(x)]++; 37 update(x); 38 } 39 for(int i=0;i<n;i++) 40 cout<<num[i]<<endl; 41 } 42 }
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/ainixu1314/p/3888672.html