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.

一天,杰夫得到了一个长度为 nn 的整数序列 a1,a2,…,ana_1, a_2, \dots, a_n。他立刻决定分析这个序列。为此,他需要找出所有满足以下条件的值 xx:

  • xx 出现在序列 aa 中;
  • 考察序列 aa 中所有等于 xx 的元素的位置(即所有满足 ai=xa_i = x 的下标 ii)。将这些位置按升序排列后,必须构成一个等差数列。

请帮助杰夫找出所有满足题目条件的 xx。

输入格式

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.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)。下一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1051 \leq a_i \leq 10^5)。这些数字以空格分隔。

输出格式

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.

第一行输出整数 tt —— 有效的 xx 的个数。接下来的 tt 行中,每行输出两个整数 xx 和 pxp_x,其中 xx 是当前符合条件的值,pxp_x 是该等差数列中相邻数字的公差(若 xx 在序列中恰好出现一次,则 pxp_x 必须为 00)。请按 xx 升序输出这些数对。

输入输出样例

  • 输入#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=0p_2 = 0。

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

首页