#9388. [USACO13NOV] Crowded Cows S

    ID: 9388 传统题 1000ms 125MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P30882013二分USACO单调队列排序队列ST 表

[USACO13NOV] Crowded Cows S

[USACO13NOV] Crowded Cows S

题目描述

Farmer John's $N$ cows ($1 \le N \le 50,000$) are grazing along a one-dimensional fence. Cow $i$ is standing at location $x_i$ and has height $h_i$ ($1 \le x_i,h_i \le 1,000,000,000$).

A cow feels "crowded" if there is another cow at least twice her height within distance DD on her left, and also another cow at least twice her height within distance DD on her right (1≤D≤1,000,000,0001 \le D \le 1,000,000,000). Since crowded cows produce less milk, Farmer John would like to count the number of such cows. Please help him.

输入格式

* Line $1$: Two integers, $N$ and $D$.
  • Lines 2..1+N2..1+N: Line i+1i+1 contains the integers xix_i and hih_i. The locations of all NN cows are distinct.

输出格式

* Line $1$: The number of crowded cows.
6 4 
10 3 
6 2 
5 3 
9 7 
3 6 
11 2 
2 

提示

There are $6$ cows, with a distance threshold of $4$ for feeling crowded. Cow #1 lives at position $x=10$ and has height $h=3$, and so on.

The cows at positions x=5x=5 and x=6x=6 are both crowded. 标签: P3088|2013|二分|USACO|单调队列|排序|队列|ST 表

来源

P3088|[USACO13NOV] Crowded Cows S