#[allow(unused)]usestd::collections::*;usestd::io::{BufRead,BufWriter,Write};#[allow(unused)]fnmain(){let sin =std::io::stdin();let scan =&mutScanner::new(sin.lock());let sout =std::io::stdout();let out =&mutBufWriter::new(sout.lock());run(scan, out);}pubstructScanner<R>{
reader:R,
buffer:Vec<String>,}impl<R:::std::io::BufRead>Scanner<R>{pubfnnew(reader:R)->Self{Self{
reader,
buffer:vec![],}}pubfntoken<T:::std::str::FromStr>(&mutself)->T{loop{ifletSome(token)=self.buffer.pop(){return token.parse().ok().expect("Failed parse");}letmut input =String::new();self.reader.read_line(&mut input).expect("Failed read");self.buffer = input.split_whitespace().rev().map(String::from).collect();}}#[allow(unused)]pubfntoken_bytes(&mutself)->Vec<u8>{let s =self.token::<String>();return s.as_bytes().into();}}// BIT 156 mspubfnsolve(scan:&mutScanner<implBufRead>, out:&mutimplWrite){let n = scan.token::<usize>();letmut a =Vec::new();letmut hs =Vec::new();for i in0..n {let l = scan.token::<i64>();let r = scan.token::<i64>();
hs.extend([l,r]);
a.push((r, l, i))}
a.sort_unstable();
hs.sort_unstable();letmut p =BIT::new(n*2);letmut ans =vec![0; n];for&(_, l, i)in a.iter(){let z = hs.partition_point(|x|*x<l);
ans[i]= p.sum_interval(z+1,n*2+1);
p.add_point(z+1,1);}for v in ans {writeln!(out,"{}", v).ok();}}pubfnrun(scan:&mutScanner<implBufRead>, out:&mutimplWrite){solve(scan, out)}// https://codeforces.com/problemset/problem/652/D// 本模板由 https://github.com/liuliangcan/play_with_python/blob/main/tools/gen_code_tool/gen_template.py 自动生成;中文题面描述可移步pubstructBIT{
c:Vec<i64>,
n:usize,}implBIT{pubfnnew(n:usize)->Self{Self{
c:vec![0; n +2],
n: n,}}/// 给下标i位置+v,注意i是1-indexedpubfnadd_point(&mutself,mut i:usize, v:i64){while i <=self.n {while i <=self.n {self.c[i]+= v;
i +=self.low_bit(i);}}}/// 计算[..i]的前缀和,包含i,注意下标1-indexedpubfnsum_prefix(&mutself,mut i:usize)->i64{letmut s =0;while i >=1{
s +=self.c[i];
i &= i -1;}return s;}/// 计算[l,r]闭区间的和,注意下标1-indexed#[allow(unused)]pubfnsum_interval(&mutself, l:usize, r:usize)->i64{returnself.sum_prefix(r)-self.sum_prefix(l -1);}pubfnlow_bit(&self, x:usize)->usize{let x = x asi64;return(x &(-x))asusize;}/// 查找[i..]后第一个>=0的位置,包含i,注意i是1-indexedpubfnmin_right(&mutself, i:usize)->usize{let p =self.sum_prefix(i);if i ==1{if p >0{return i;}}else{if p >self.sum_prefix(i -1){return i;}}let(mut l,mut r)=(i,self.n +1);while l +1< r {let mid =(l + r)>>1;ifself.sum_prefix(mid)> p {
r = mid
}else{
l = mid
}}return r;}}