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. eclipse中代码整体左右移动的方法

    1.向左:将要移动的代码选中,然后按TAB键2.向右:将要移动的代码选中,然后按shift+tab键 kettas:  2009-8-21

  2. CSS (层叠样式表)

    层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言.CSS不仅可以静态 ...

  3. 让System.Drawing.Bitmap可以在linux运行

    .net core的bitmap使用的是以下类库,但无法在linux运行 https://github.com/CoreCompat/CoreCompat 在linux运行需要安装runtime.li ...

  4. Typescript编译设置

    TypeScript MSBuild编译选项,用记事本打开工程文件,进行修改,如<TypeScriptGeneratesDeclarations>true</TypeScriptGe ...

  5. Swift 3到5.1新特性整理

    本文转载自:https://hicc.me/whats-new-in-swift-3-to-5-1/,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有. Hipo 2.0 重写从 Swif ...

  6. tab切换案例

    做个简单的tab切换效果,分别于jquery和js操作 (1)jQuery操作 先看下效果: <!DOCTYPE html> <html lang="en"> ...

  7. Fang Fang HDU - 5455 (思维题)

    Fang Fang says she wants to be remembered. I promise her. We define the sequence FF of strings. F0 = ...

  8. web前端学习总结--HTML

    web三要素: 浏览器:向服务器发起请求,下载服务器中的网页(HTML),然后执行HTML显示出内容 服务器:接受浏览器的请求,发送相应的页面到浏览器 HTTP协议:浏览器与服务器的通讯协议. HTM ...

  9. ansible - playbook(剧组)

    目录 ansible - playbook(剧组) 常用命令 五种传参方式 常用元素详解 tags handlers template when 循环 嵌套循环 ansible - playbook( ...

  10. web开发如何使用高德地图API(四)通过AMap.Marker自定义标点

    说两句: 以下内容除了我自己写的部分,其他部分在高德开放平台都有(可点击外链访问). 我所整理的内容以实际项目为基础希望更有针对性的,更精简. 点击直奔主题. 准备工作: 首先,注册开发者账号,成为高 ...