CF1156E.Special Segments of Permutation

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a permutation pp of nn integers 11 , 22 , ..., nn (a permutation is an array where each element from 11 to nn occurs exactly once).

Let's call some subsegment p[l,r]p[l, r] of this permutation special if pl+pr=maxi=lrpip_l + p_r = \max \limits_{i = l}^{r} p_i . Please calculate the number of special subsegments.

输入格式

The first line contains one integer nn ( 3n21053 \le n \le 2 \cdot 10^5 ).

The second line contains nn integers p1p_1 , p2p_2 , ..., pnp_n ( 1pin1 \le p_i \le n ). All these integers are pairwise distinct.

输出格式

Print the number of special subsegments of the given permutation.

输入输出样例

  • 输入#1

    5
    3 4 1 5 2
    

    输出#1

    2
    
  • 输入#2

    3
    1 3 2
    

    输出#2

    1
    

说明/提示

Special subsegments in the first example are [1,5][1, 5] and [1,3][1, 3] .

The only special subsegment in the second example is [1,3][1, 3] .

首页