CF1156E.Special Segments of Permutation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation p of n integers 1 , 2 , ..., n (a permutation is an array where each element from 1 to n occurs exactly once).
Let's call some subsegment p[l,r] of this permutation special if pl+pr=i=lmaxrpi . Please calculate the number of special subsegments.
输入格式
The first line contains one integer n ( 3≤n≤2⋅105 ).
The second line contains n integers p1 , p2 , ..., pn ( 1≤pi≤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] and [1,3] .
The only special subsegment in the second example is [1,3] .