作者:男孩花朵 | 来源:互联网 | 2023-08-16 08:33
1043: Radical loves integer sequences
Time Limit: 1 Sec
Memory Limit: 128 MB
Submit: 36
Solved: 4
[
Submit][
Status][
Web Board]
Description
One day Radical got hold of an integer sequence a1, a2, ..., an of length n. He 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 ai = x). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Radical, find all x that meet the problem conditions.
Input
The first line contains integer n (1 ≤ n ≤ 105). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 105). The numbers are separated by spaces.
Output
In the first line print integer t — the number of valid x. On each of the next t lines print two integers x and px, where x is current suitable value, px is the common difference between numbers in the progression (if x occurs exactly once in the sequence, px must equal 0).
Print the pairs in the order of increasing x.
Sample Input
1
3
4
9 9 3 5
Sample Output
1
3 0
3
3 0
5 0
9 1
这题前几次看真心没看懂,今天下午看了一下,发现是判断同一个数字出现的下标是否是等差数列,是则输出公差,否则则不输出。
没什么算法,就是记录时判断麻烦点..
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include