CF352B.Jeff and Periods
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
One day Jeff got hold of an integer sequence _a_1, _a_2, ..., a__n of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold:
- x occurs in sequence a.
- Consider all positions of numbers x in the sequence a (such i, that a__i = x). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all x that meet the problem conditions.
一天,杰夫得到了一个长度为 n 的整数序列 a1,a2,…,an。他立刻决定分析这个序列。为此,他需要找出所有满足以下条件的值 x:
- x 出现在序列 a 中;
- 考察序列 a 中所有等于 x 的元素的位置(即所有满足 ai=x 的下标 i)。将这些位置按升序排列后,必须构成一个等差数列。
请帮助杰夫找出所有满足题目条件的 x。
输入格式
The first line contains integer n (1 ≤ n ≤ 105). The next line contains integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 105). The numbers are separated by spaces.
第一行包含一个整数 n(1≤n≤105)。下一行包含 n 个整数 a1,a2,…,an(1≤ai≤105)。这些数字以空格分隔。
输出格式
In the first line print integer t — the number of valid x. On each of the next t lines print two integers x and p__x, where x is current suitable value, p__x is the common difference between numbers in the progression (if x occurs exactly once in the sequence, p__x must equal 0). Print the pairs in the order of increasing x.
第一行输出整数 t —— 有效的 x 的个数。接下来的 t 行中,每行输出两个整数 x 和 px,其中 x 是当前符合条件的值,px 是该等差数列中相邻数字的公差(若 x 在序列中恰好出现一次,则 px 必须为 0)。请按 x 升序输出这些数对。
输入输出样例
输入#1
1 2
输出#1
1 2 0
输入#2
8 1 2 1 3 1 2 1 5
输出#2
4 1 2 2 4 3 0 5 0
说明/提示
In the first test 2 occurs exactly once in the sequence, ergo _p_2 = 0.
在第一个测试中,2 在序列中恰好出现一次,因此 p2=0。
输入解题思路,AI测评打分。不知道怎么写?