4454: Arithmetic Sequence

内存限制:128 MB 时间限制:3 S 标准输入输出
题目类型:传统 评测方式:Special Judge 上传者:
提交:0 通过:0

题目描述

A sequence of numbers is said to be arithmetic if there is a constant difference between successive elements.

Given an array of integers, your task is to count the number of contiguous subarrays which can be rearranged to form an arithmetic sequence.

输入格式

There will be at most 200 test cases. Each case begins with one integer n(1 ≤ n ≤ 105), the length of the array. The next line contains n integers, denoting the array. The array is a permutation of values 1, 2, …, n. The size of the whole input file does not exceed 2MB.

输出格式

For each test case, print the number of contiguous subarrays which can be rearranged to form an arithmetic sequence.

输入样例 复制

3
2 3 1
4
1 4 2 3

输出样例 复制

6
9

数据范围与提示

For the second sample, the following 9 subarrays can be rearranged to form an arithmetic sequence: [1], [4], [2], [3], [1, 4], [4, 2], [2, 3], [4, 2, 3] ( [2, 3, 4]), [1, 4, 2, 3] ( [1, 2, 3, 4]).