#P7033. [NWRRC2016] CodeCoder vs TopForces

[NWRRC2016] CodeCoder vs TopForces

题目描述

Competitive programming is very popular in Byteland. In fact, every Bytelandian citizen is registered at two programming sites -- CodeCoder and TopForces. Each site maintains its own proprietary rating system. Each citizen has a unique integer rating at each site that approximates their skill. Greater rating corresponds to better skill.

People of Byteland are naturally optimistic. Citizen A thinks that he has a chance to beat citizen B in a programming competition if there exists a sequence of Bytelandian citizens A=P0,P1,...,Pk=BA = P_{0}, P_{1},...,P_{k} = B for some k1k \ge 1 such that for each i(0i<k),Pii (0 \le i < k) , P_{i} has higher rating than Pi+1P_{i+1} at one or both sites.

Each Bytelandian citizen wants to know how many other citizens they can possibly beat in a programming competition.

输入格式

The first line of the input contains an integer nn -- the number of citizens (1n100000)(1 \le n \le 100 000) . The followingnThe following n lines contain information about ratings. The i-th of them contains two integers CCiand TFiCC_{i} and TF_{i} -- ratings of the i-th citizen at CodeCoder and TopForces (1CCi,TFi106).(1 \le CC_{i}, TF_{i} \le 10^{6}). All the ratings at each site are distinct.

输出格式

For each citizen ii output an integer bib_{i} -- how many other citizens they can possibly beat in a programming competition. Each bib_{i} should be printed in a separate line, in the order the citizens are given in the input.

题目大意

  • nn 个人,每个人有两个能力值 CCiCC_iTFiTF_i。第 ii 个人能打败第 jj 个人当且仅当 CCi>CCjCC_i >CC_jTFi>TFjTF_i>TF_j

  • 强的关系具有传递性,也就是说 iijj 强,jjkk 强,那么 iikk 强。 求出每个人最多可以打败的人的个数。

  • n105n \leq10^5CCi,TFi106CC_i,TF_i \leq10^6,数据保证 CCiCC_i 两两不同、TTiTT_i 两两不同。

4
2 3
3 2
1 1
4 5

2
2
0
3

提示

Time limit: 2 s, Memory limit: 256 MB.