标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 16693 | Accepted: 5583 |
Description
Input
Output
Sample Input
3 1 2 0 3 3 4 0
Sample Output
1 0 0
Hint
Source
题目大意就是要你求出每个集合是几个集合的真子集
然而我一开始以为要求每个集合有几个真子集,所以想了良久没搞定……此题类似Stars,只不过内题是已经排好序的,这题不是。
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <cstdlib> 5 #include <queue> 6 #include <stack> 7 #include <vector> 8 #include <iostream> 9 #include "algorithm" 10 using namespace std; 11 typedef long long LL; 12 const int MAX=100005; 13 int n; 14 int sum[MAX]; 15 int ans[MAX]; 16 struct Seg{ 17 int a,b,c; 18 }seg[MAX]; 19 void add(int x,int y){ 20 for (;x<=n;sum[x]+=y,x+=(x&-x)); 21 } 22 int search(int x){ 23 int an(0); 24 for (;x>0;an+=sum[x],x-=(x&-x)); 25 return an; 26 } 27 bool cmp(Seg x,Seg y){ 28 if (x.b!=y.b) 29 return x.b>y.b; 30 else 31 return x.a<y.a; 32 } 33 int main(){ 34 freopen ("cows.in","r",stdin); 35 freopen ("cows.out","w",stdout); 36 int i,j; 37 while (1) 38 {scanf("%d",&n); 39 if (n==0) 40 break; 41 for (i=1;i<=n;i++) 42 {scanf("%d%d",&seg[i].a,&seg[i].b); 43 seg[i].c=i; 44 } 45 sort(seg+1,seg+n+1,cmp); 46 memset(sum,0,sizeof(sum)); 47 memset(ans,0,sizeof(ans)); 48 for (i=1;i<=n;i++) 49 {if (i!=1 && seg[i].a==seg[i-1].a && seg[i].b==seg[i-1].b) 50 ans[seg[i].c]=ans[seg[i-1].c]; 51 else 52 ans[seg[i].c]=search(seg[i].a+1); 53 add(seg[i].a+1,1); 54 } 55 for (i=1;i<n;i++) 56 printf("%d ",ans[i]); 57 printf("%d\n",ans[n]); 58 } 59 return 0; 60 }
标签:
原文地址:http://www.cnblogs.com/Michaelzzn/p/5764272.html