问题 G: HILO

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

Bessie 有一个数 $x+0.5$,其中 $x$ 是某个 $0$ 到 $N$ 之间的整数($1\le N\le 2 \cdot 10^5$)。  

Elsie 正试着猜这个数。她可以以如下形式对于某个 $1$ 到 $N$ 之间的整数提问:「$i$ 是大了还是小了?」如果 $i$ 大于 $x+0.5$,Bessie 会回答 "HI",如果 $i$ 小于 $x+0.5$ 则回答 "LO"。

Elsie 想到了以下猜测 Bessie 的数的策略。在进行任何猜测之前,她创建了一个包含 $N$ 个整数的序列,其中从 $1$ 到 $N$ 的每个数均恰好出现一次(换句话说,这个序列是长为 $N$ 的一个排列)。然后她遍历这一列表,按列表中的数的顺序依次猜数。

然而,Elsie 会跳过所有不必要的猜测。也就是说,如果 Elsie 将要猜某个数 $i$,而 Elsie 之前已经猜过了某个 $j < i$ 并且 Bessie 回答 "HI",Elsie 不会再猜 $i$,而是继续猜序列中的下一个数。类似地,如果她将要猜某个数 $i$,而她之前已经猜过了某个 $j > i$ 并且 Bessie 回答 "LO",Elsie 不会再猜 $i$,而是继续猜序列中的下一个数。可以证明,使用这一策略,对于 Elsie 创建的任意序列,她都可以唯一确定 $x$。

如果我们将所有 Bessie 回答的 "HI" 或 "LO" 拼接成一个字符串 $S$,那么 Bessie 说 "HILO" 的次数为 $S$ 等于 "HILO" 的长为 $4$ 的子串数量。

Bessie 知道 Elsie 将要使用这一策略;此外,她还知道 Elsie 将要使用的排列。然而, Bessie 尚未决定选用哪个值 $x$。

帮助 Bessie 对于每个值 $x$ 求出她会说 "HILO" 的次数。

## 输入格式

输入的第一行包含 $N$。

第二行包含 Elsie 的长为 $N$ 的排列。

## 输出格式

对于从 $0$ 到 $N$ 的每一个 $x$,输出一行,包含 Bessie 会说 HILO 的次数。

## 样例 #1

### 样例输入 #1

```
5
5 1 2 4 3
```

### 样例输出 #1

```
0
1
1
2
1
0
```

## 提示

【样例解释】

对于 $x=0$,Bessie 会说 "HIHI",总计零次 "HILO"。

对于 $x=2$,Bessie 会说 "HILOLOHIHI",总计一次 "HILO"。

对于 $x=3$,Bessie 会说 "HILOLOHILO",总计两次 "HILO"。

【数据范围】

- 测试点 1-4 满足 $N \leq 5000$。
- 测试点 5-8 为均匀随机的排列。
- 测试点 9-20 没有额外限制。


Bessie knows a number x+0.5 where xx is some integer between 0 to N, inclusive (1≤N≤2⋅105).

Elsie is trying to guess this number. She can ask questions of the form "is ii high or low?" for some integer ii between 1 and N, inclusive. Bessie responds by saying "HI" if ii is greater than x+0.5, or "LO" if ii is less than x+0.5.

Elsie comes up with the following strategy for guessing Bessie's number. Before making any guesses, she creates a list of N numbers, where every number from 11 to N occurs exactly once (in other words, the list is a permutation of size N). Then she goes through the list, guessing numbers that appear in the list in order.

However, Elsie skips any unnecessary guesses. That is, if Elsie is about to guess some number ii and Elsie previously guessed some j<i and Bessie responded with "HI", Elsie will not guess ii and will move on to the next number in the list. Similarly, if she is about to guess some number ii and she previously guessed some j>i and Bessie responded with "LO", Elsie will not guess ii and will move on to the next number in the list. It can be proven that using this strategy, Elsie always uniquely determines xx regardless of the permutation she creates.

If we concatenate all of Bessie's responses of either "HI" or "LO" into a single string SS, then the number of times Bessie says "HILO" is the number of length 4 substrings of S that are equal to "HILO."

Bessie knows that Elsie will use this strategy; furthermore, she also knows the exact permutation that Elsie will use. However, Bessie has not decided on what value of x to choose.

Help Bessie determine how many times she will say "HILO" for each value of x.

输入格式

The first line contains N.

The second line contains Elsie's permutation of size N.

输出格式

For each xx from 00 to N, inclusive, output the number of times Bessie will say HILO on a new line.

输入样例 复制

5
5 1 2 4 3

输出样例 复制

0
1
1
2
1
0

数据范围与提示

For x=0, Bessie will say "HIHI," for a total of zero "HILO"s.

For x=2, Bessie will say "HILOLOHIHI," for a total of one "HILO".

For x=3, Bessie will say "HILOLOHILO", for a total of two "HILO"s.

SCORING:

  • Tests 1 to 4 satisfy N≤5000N≤5000.
  • Tests 5 to 8 have a uniformly random permutation.
  • Tests 9 to 20 satisfy no further constraints.