P3608 [USACO17JAN]Balanced Photo平衡的照片

• 457通过
• 753提交
• 题目提供者 FarmerJohn2
• 评测方式 云端评测
• 标签 前缀和 枚举,暴力 树状数组 USACO 2017
• 难度 提高+/省选-
• 时空限制 1000ms / 128MB
• 提示：收藏到任务计划后，可在首页查看。

题目描述

Farmer John is arranging his $N$ cows in a line to take a photo ($1 \leq N \leq 100,000$). The height of the $i$th cow in sequence is $h_i$, and the heights of all cows are distinct.

As with all photographs of his cows, FJ wants this one to come out looking as nice as possible. He decides that cow $i$ looks "unbalanced" if $L_i$ and $R_i$ differ by more than factor of 2, where $L_i$ and $R_i$ are the number of cows taller than $i$ on her left and right, respectively. That is, $i$ is unbalanced if the larger of $L_i$ and $R_i$ is strictly more than twice the smaller of these two numbers. FJ is hoping that not too many of his cows are unbalanced.

FJ正在安排他的N头奶牛站成一排来拍照。（1<=N<=100,000)序列中的第i头奶牛的高度是h[i]，且序列中所有的奶牛的身高都不同。

就像他的所有牛的照片一样，FJ希望这张照片看上去尽可能好。他认为，如果L[i]和R[i]的数目相差2倍以上的话，第i头奶牛就是不平衡的。（L[i]和R[i]分别代表第i头奶牛左右两边比她高的数量）。如果L[i]和R[i]中较大者比较小者的数量严格多两倍的话，这头奶牛也是不平衡的。FJ不希望他有太多的奶牛不平衡。

请帮助FJ计算不平衡的奶牛数量。

输入输出格式

输入格式：

The first line of input contains $N$. The next $N$ lines contain $h_1 \ldots h_N$, each a nonnegative integer at most 1,000,000,000.

第一行一个整数N。接下N行包括H到H[n]，每行一个非负整数（不大于1,000，000，000)。

输出格式：

Please output a count of the number of cows that are unbalanced.

请输出不平衡的奶牛数量。

输入输出样例

输入样例#1： 复制
7
34
6
23
0
5
99
2
输出样例#1： 复制
3

说明

感谢 @XY星系质量PK 的翻译

提示
标程仅供做题后或实在无思路时参考。
请自觉、自律地使用该功能并请对自己的学习负责。
如果发现恶意抄袭标程，将按照I类违反进行处理。