标签:nbsp oid efi width node ted first ota clu
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 19673 | Accepted: 6699 |
Description
Input
Output
Sample Input
3
1 2
0 3
3 4
0
Sample Output
1 0 0
Hint
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #define N 100005 6 #define mem(a) memset(a,0,sizeof(a)) 7 using namespace std; 8 struct Node{ 9 int x,y,id; 10 }; 11 int val[N]; 12 int lowbit(int a){ 13 return a&(-a); 14 } 15 int tree[N]; 16 Node node[N]; 17 18 void update(int x){ 19 while(x<=N){ 20 tree[x]++; 21 x+=lowbit(x); 22 } 23 } 24 25 bool cmp(Node a,Node b){ 26 if(a.y==b.y) 27 return a.x<b.x; 28 return a.y>b.y; 29 } 30 int query(int x){ 31 int sum=0; 32 while(x>0){ 33 sum+=tree[x]; 34 x-=lowbit(x); 35 } 36 return sum; 37 } 38//void test(){ 39// cout<<"***"<<endl; 40// } 41 int main() { 42 int n; 43 while(scanf("%d",&n)&&n){ 44 mem(tree); 45 // mem(node); 46 mem(val); 47 for(int i=0;i<n;i++){ 48 scanf("%d%d",&node[i].x,&node[i].y); 49 node[i].id=i; 50 node[i].x++; 51 node[i].y++; 52 } 53 sort(node,node+n,cmp); 54 val[node[0].id]=query(node[0].x); 55 update(node[0].x); 56 57 for(int i=1;i<n;i++){ 58 if(node[i].x==node[i-1].x&&node[i].y==node[i-1].y){ 59 val[node[i].id]=val[node[i-1].id]; 60 }else{ 61 val[node[i].id]=query(node[i].x); 62 }update(node[i].x); 63 } 64 65 // test(); 66 for(int i=0;i<n;i++){ 67 if(i!=n-1) 68 printf("%d ",val[i]); 69 else 70 printf("%d\n",val[i]); 71 } 72 } 73 return 0; 74 }
标签:nbsp oid efi width node ted first ota clu
原文地址:http://www.cnblogs.com/zllwxm123/p/7308933.html