B. Jeff and Periods
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

One day Jeff got hold of an integer sequence a1, a2, ..., an 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 ai = x). These numbers, sorted in the increasing order, must form an arithmetic progression.

Help Jeff, 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 test(s)
Input
1
2
Output
1
2 0
Input
8
1 2 1 3 1 2 1 5
Output
4
1 2
2 4
3 0
5 0
 #include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
const int Max=;
using namespace std;
int main()
{
int n,x;
int vis[Max],p[Max];
while(~scanf("%d",&n))
{
int k = ,i,j;
vector<int>G[Max];
memset(vis,,sizeof(vis));
for (i = ; i < n; i++)
{
scanf("%d",&x);
G[x].push_back(i);//将所有x的位置存入vector中
if (!vis[x])
{
vis[x] = ;
p[k++] = x;
} }
int cnt = ;
memset(vis,-,sizeof(vis));
for (j = ; j < k; j++)
{
int len = G[p[j]].size();
if (len==)
{
++cnt;
vis[p[j]]= ;
continue;
}
int d = G[p[j]][]-G[p[j]][];//求公差
for (i = ; i < len; i++)
{
if (G[p[j]][i]-G[p[j]][i-]!=d)
break;
}
if (i >= len)//说明p[j]的各位置是等差数列
{
++cnt;
vis[p[j]] = d;//表示p[j]各位置的公差为d
}
}
printf("%d\n",cnt);
sort(p, p+k);
for (i = ; i < k ; i++)
{
if (vis[p[i]]!=-)
{
printf("%d %d\n",p[i],vis[p[i]]);
}
}
}
return ;
}

B. Jeff and Periods(cf)的更多相关文章

  1. Codeforces Round #204 (Div. 2)->B. Jeff and Periods

    B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces 352B - Jeff and Periods

    352B - Jeff and Periods 思路:水题,考验实现(implementation)能力,来一波vector[允悲]. 代码: #include<bits/stdc++.h> ...

  3. cf B. Jeff and Periods

    http://codeforces.com/contest/352/problem/B #include <cstdio> #include <cstring> #includ ...

  4. CF352B Jeff and Periods 模拟

    One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decide ...

  5. A. Jeff and Digits(cf)

    A. Jeff and Digits time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. codeforces B. Jeff and Periods 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/B 题目意思:给出一个长度为n的序列   a1, a2, ..., an(序号i,1 <= i ...

  7. code forces Jeff and Periods

    /* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...

  8. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  9. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

随机推荐

  1. js 获取 checkbox[] 值

    $("#btnAdd1").click(function () { console.log($("form").serialize()); var checkb ...

  2. MVCHelper 请求检验

    public class MVCHelper { //有 两 个ModelStateDictionary类,别弄混乱了要使用 System.Web.Mvc 下的 //如果添加引用中找不到System. ...

  3. git连接github mac

    话不多说,终端里的代码直接复制过来 Last login: Fri May 17 21:45:31 on ttys000 liuduoduodeMacBook-Air:~ liuxiangyang$ ...

  4. ubuntu系统中java开发环境的搭建

    Java环境可选择 Oracle 的 JDK,或是 OpenJDK,按http://wiki.apache.org/hadoop/HadoopJavaVersions中说的,新版本在 OpenJDK ...

  5. 【模板】Hash

    洛谷3370 这题煞笔的吧QAQ......排序去重或者Map都可以 #include<cstdio> #include<map> #include<string> ...

  6. Thinkphp5跨域问题

    关于代码分离可能会遇到json传输接收不到的问题(可能00) 起初我百度到解决此问题可以用jsonp来发送并接受,可是这只是一时之计 以后也会不方便所以我发现了一下方法 在app顶层创建文件commo ...

  7. 【codeforces 527B】Error Correct System

    [题目链接]:http://codeforces.com/contest/527/problem/B [题意] 给你两个字符串; 允许你交换一个字符串的两个字符一次: 问你这两个字符串最少会有多少个位 ...

  8. Maven学习总结(28)——Maven+Nexus+Myeclipse集成

    Maven简介 Maven 是一个基于项目对象模型(POM)的,提倡约定优于配置(ConventionOver Configuration)的,跨平台的项目管理和构建自动化工具. 首先它是一个优秀的构 ...

  9. (45). Spring Boot MyBatis连接Mysql数据库【从零开始学Spring Boot】

    大家在开发的时候,会喜欢jdbcTemplate操作数据库,有喜欢JPA操作数据库的,有喜欢MyBatis操作数据库的,对于这些我个人觉得哪个使用顺手就使用哪个就好了,并没有一定要使用哪个,个人在实际 ...

  10. 暑假集训D17总结

    考试 玄学的一次考试= = T1乱搞 只会乱搞出前二十分  然后真的拿了二十分 T2模拟 自己造数据 没有一个是在十分钟内跳出来的 然后竟然A了 T3暴力 觉得如果老爷机心情不好就会被卡到20  然后 ...