CF1156E.Special Segments of Permutation

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

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=max⁡i=lrpip_l + p_r = \max \limits_{i = l}^{r} p_i. Please calculate the number of special subsegments.

给你一个 nn 个整数 1,2,…,n1, 2, \dots, n 的排列 pp(排列是指每个从 11 到 nn 的整数恰好出现一次的数组)。

我们称该排列的某个子段 p[l,r]p[l, r] 是特殊的,当且仅当 pl+pr=max⁡i=lrpip_l + p_r = \max \limits_{i = l}^{r} p_i。请计算特殊子段的个数。

输入格式

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

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

第一行包含一个整数 nn(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5)。

第二行包含 nn 个整数 p1p_1, p2p_2, ..., pnp_n(1≤pi≤n1 \le p_i \le n)。这些整数两两互不相同。

输出格式

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].

第一个样例中的特殊子区间为 [1,5][1, 5] 和 [1,3][1, 3]。

第二个样例中唯一的特殊子区间为 [1,3][1, 3]。

输入解题思路,AI测评打分。不知道怎么写?

首页