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. ProE复杂曲线方程:Python Matplotlib 版本代码(L系统,吸引子和分形)

    对生长自动机的研究由来已久,并在计算机科学等众多学科中,使用元胞自动机的概念,用于生长模拟.而复杂花纹的生成,则可以通过重写一定的生长规则,使用生成式来模拟自然纹理.当然,很多纹理是由人本身设计的,其 ...

  2. Go 时间相关

    >获取当前时间: t := time.Now() >获取当天开始.结束时间: tm1 := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, ...

  3. (转)Java任务调度框架Quartz入门教程指南(四)Quartz任务调度框架之触发器精讲SimpleTrigger和CronTrigger、最详细的Cron表达式范例

    http://blog.csdn.net/zixiao217/article/details/53075009 Quartz的主要接口类是Schedule.Job.Trigger,而触发器Trigge ...

  4. HDU_1068_Girls and Boys_二分图匹配

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. PHP 之转换excel表格中的经纬度

    <?php set_time_limit(0); include './plugin/PHPExcel/PHPExcel.php'; include './plugin/PHPExcel/PHP ...

  6. Sping——使用注解创建切面

    为讲解例子,我们首先定义一个Performance接口: package aoptest; public interface Performance { public void perform(); ...

  7. 图像处理中创建CDib类时无法选择基类类型时怎么办

    图像处理中创建CDib类时无法选择基类类型时怎么办? 类的类型选择Generic Class 在下面的篮筐里输入CObject就行了

  8. Intellij Idea 创建一个Web项目

    今天想用IDEA创建一个web项目: 准备工具 1.jdk1.7 2.tomcat6.0,由于下载的8.5没有lib目录不能配置改6.0 3.idea2019.1.2 Intellij Idea的安装 ...

  9. Scrapy Item用法示例(保存item到MySQL数据库,MongoDB数据库,使用官方组件下载图片)

    需要学习的地方: 保存item到MySQL数据库,MongoDB数据库,下载图片 1.爬虫文件images.py # -*- coding: utf-8 -*- from scrapy import ...

  10. python编程——断言

    基本语法 assert_stmt ::= "assert" expression ["," expression] assert 5 > 3 # 肯定是对 ...