CF1156E.Special Segments of Permutation
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
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.
给你一个 n 个整数 1,2,…,n 的排列 p(排列是指每个从 1 到 n 的整数恰好出现一次的数组)。
我们称该排列的某个子段 p[l,r] 是特殊的,当且仅当 pl+pr=i=lmaxrpi。请计算特殊子段的个数。
输入格式
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.
第一行包含一个整数 n(3≤n≤2⋅105)。
第二行包含 n 个整数 p1, p2, ..., pn(1≤pi≤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] and [1,3].
The only special subsegment in the second example is [1,3].
第一个样例中的特殊子区间为 [1,5] 和 [1,3]。
第二个样例中唯一的特殊子区间为 [1,3]。
输入解题思路,AI测评打分。不知道怎么写?