标签:des style blog http color os strong io
Description
Input
Output
Sample Input
3 1 2 0 3 3 4 0
Sample Output
1 0 0
x 按升序,y按降序 sort一下
x1,y1
x2,y2
如果x1==x2,y1==y2的话,sum(x2,y2)=sum(x1,y1),不能用getnum()去求覆盖(x2,y2)的区间个数
1 2
1 2
1 2
用getnum()去求第三个(1,2)的话,会得到2,但是结果应该为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,m,k,mmax; 15 int p[100100],check[100100]; 16 struct node{ 17 int x,y,id; 18 }num[101000]; 19 int cmp(node a,node b){ 20 if(a.x==b.x) return a.y>b.y; 21 return a.x<b.x; 22 } 23 void update(int pos){ 24 while(pos>=1){ 25 p[pos]+=1; 26 pos-=pos&(-pos); 27 } 28 } 29 int getnum(int pos){ 30 int sum=0; 31 while(pos<=mmax){ 32 sum+=p[pos]; 33 pos+=pos&(-pos); 34 } 35 return sum; 36 } 37 int main(){ 38 while(scanf("%d",&n),n){ 39 memset(p,0,sizeof(p)); 40 memset(check,0,sizeof(check)); 41 mmax=0; 42 for(int i=1;i<=n;i++){ 43 scanf("%d%d",&num[i].x,&num[i].y); 44 num[i].x++,num[i].y++; 45 num[i].id=i; 46 mmax=max(mmax,num[i].y); 47 } 48 sort(num+1,num+1+n,cmp); 49 check[num[1].id]=0; 50 update(num[1].y); 51 for(int i=2;i<=n;i++){ 52 if(num[i].x==num[i-1].x&&num[i].y==num[i-1].y) 53 check[num[i].id ]=check[num[i-1].id ]; 54 else 55 check[num[i].id ]=getnum(num[i].y); 56 update(num[i].y); 57 } 58 for(int i=1;i<=n;i++){ 59 if(i!=1) printf(" "); 60 printf("%d",check[i]); 61 } 62 printf("\n"); 63 } 64 }
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/ainixu1314/p/3888917.html