Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in his field is particularly good.

Farmer John has N cows (we number the cows from 1 to N). Each of Farmer John's N cows has a range of clover that she particularly likes (these ranges might overlap). The ranges are defined by a closed interval [S,E].

But some cows are strong and some are weak. Given two cows: cowi and cowj, their favourite clover range is [Si, Ei] and [Sj, Ej]. If Si <= Sj and Ej <= Ei and Ei - Si > Ej - Sj, we say that cowi is stronger than cowj.

For each cow, how many cows are stronger than her? Farmer John needs your help!

 

Input

The input contains multiple test cases. 
For each test case, the first line is an integer N (1 <= N <= 105), which is the number of cows. Then come N lines, the i-th of which contains two integers: S and E(0 <= S < E <= 105) specifying the start end location respectively of a range preferred by some cow. Locations are given as distance from the start of the ridge.

The end of the input contains a single 0.

 

Output

For each test case, output one line containing n space-separated integers, the i-th of which specifying the number of cows that are stronger than cowi.

 

Sample Input

3
1 2
0 3
3 4
0
 

Sample Output

1 0 0
/*先按e值从大到小,相同就x从小到大
排好后由于前面的E值已经比当前点大,只要找出S值比当前小的就满足
注意坐标+1,处理相同的,s,e
建模是关键*/
#include"iostream"
#include"cstdio"
#include"cstring"
#include"algorithm"
#define MAX 100005
using namespace std;
struct node{
int e,s;
int id;
}cow[MAX];
int N;
int c[MAX];
int a[MAX];
int cmp(const node &a,const node &b)
{
if(a.e==b.e)
return b.s > a.s;
else
return a.e > b.e;
}
int lowbit(int x)
{
return x&(-x);
}
int getsum(int x)
{
int sum=;
while(x>)
{
sum+=c[x];
x-=lowbit(x);
}
return sum;
}
void updata(int x,int d)
{
while(x<=MAX)
{
c[x]+=d;
x+=lowbit(x);
}
}
int main()
{
int i;
while(scanf("%d",&N)!=EOF)
{
if(!N)
break;
memset(c,,sizeof(c));
memset(a,,sizeof(a));
for(int i=;i<N;i++)
{
scanf("%d %d",&cow[i].s,&cow[i].e);
cow[i].s++;
cow[i].e++;
cow[i].id=i;
}
sort(cow,cow+N,cmp);
a[cow[].id]=;
updata(cow[].s,);
for( i=;i<N;i++)
{
if(cow[i].s==cow[i-].s&&cow[i].e==cow[i-].e)
a[cow[i].id]=a[cow[i-].id];
else
a[cow[i].id]=getsum(cow[i].s);
updata(cow[i].s,);
}
printf("%d",a[]);
for(int i=;i<N;i++)
printf(" %d",a[i]);
printf("\n");
}
return ;
}

Cows的更多相关文章

  1. [LeetCode] Bulls and Cows 公母牛游戏

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  2. POJ 2186 Popular Cows(Targin缩点)

    传送门 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31808   Accepted: 1292 ...

  3. POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)

    传送门 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46727   Acce ...

  4. LeetCode 299 Bulls and Cows

    Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...

  5. [Leetcode] Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  6. 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列

    第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...

  7. POJ2186 Popular Cows [强连通分量|缩点]

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31241   Accepted: 12691 De ...

  8. Poj2186Popular Cows

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31533   Accepted: 12817 De ...

  9. [poj2182] Lost Cows (线段树)

    线段树 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacula ...

  10. 【POJ3621】Sightseeing Cows

    Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8331   Accepted: 2791 ...

随机推荐

  1. ESB 客户端调用 处理类

    esb package com.isoftstone.synchronize.entrance; import java.io.File; import java.text.SimpleDateFor ...

  2. ThinkPad X200s 安装 Mac OSX

    ===================先说一下注意事项================== 无论任何安装方法(U盘.光盘)不能进入安装界面,或者鼠标无法移动.那就在变色龙引导界面加入以下代码 cpus ...

  3. 关于诺顿身份安全2013独立版(Norton Identity Safe)

    现在身份安全这货好像从诺顿的套装当中独立出来了,出了中文版.其实诺顿的Web信誉做得还是不错的,当然天朝不要有太大期望.只是公认的做web信誉做得最好的应该就是趋势科技和诺顿,所以诺顿的身份安全也许还 ...

  4. 好用的编辑框布局控件TdxLayoutControl

    TdxLayoutControl是编辑框的容器,里面的编辑框可以自动对齐,自由拖放,异常方便.

  5. Python类的探讨

    我们下面的探讨基于Python3,我实际测试使用的是Python3.2,Python3与Python2在类函数的类型上做了改变 1,类定义语法  Python类定义以关键字class开头,一个类定义例 ...

  6. css之clear属性

    clear属性用来设置元素左右两边是否可以存在浮动元素. 它的值包括:left,right,both,none.其中none代表左右两边可以出现浮动元素.

  7. 数据库:mongodb与关系型数据库相比的优缺点

      与关系型数据库相比,MongoDB的优点:①弱一致性(最终一致),更能保证用户的访问速度:举例来说,在传统的关系型数据库中,一个COUNT类型的操作会锁定数据集,这样可以保证得到“当前”情况下的精 ...

  8. Opencv2系列学习笔记10(提取连通区域轮廓)

    连通区域指的是二值图像中相连像素组成的形状.而内.外轮廓的概念及opencv1中如何提取二值图像的轮廓见我的这篇博客:http://blog.csdn.net/lu597203933/article/ ...

  9. installshield 注册dll

    function OnFirstUIAfter() STRING szTitle, szMsg1, szMsg2, szOpt1, szOpt2; NUMBER bOpt1, bOpt2; begin ...

  10. Jquery基础:append、prepend、after、before、appendTo的区别

    append() 是在被选元素的结束标签前面(即改被选元素的内部)插入指定内容. after() 是在被选元素的结束标签后面(即该被选元素的外部)插入指定的内容. appendTo() 仍然是在被选元 ...