博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF352B Jeff and Periods 模拟
阅读量:6913 次
发布时间:2019-06-27

本文共 3470 字,大约阅读时间需要 11 分钟。

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.

Examples
Input
Copy
1 2
Output
Copy
1 2 0
Input
Copy
8 1 2 1 3 1 2 1 5
Output
Copy
4 1 2 2 4 3 0 5 0
Note

In the first test 2 occurs exactly once in the sequence, ergo p2 = 0.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
//#pragma GCC optimize(2)using namespace std;#define maxn 200005#define inf 0x7fffffff//#define INF 1e18#define rdint(x) scanf("%d",&x)#define rdllt(x) scanf("%lld",&x)#define rdult(x) scanf("%lu",&x)#define rdlf(x) scanf("%lf",&x)#define rdstr(x) scanf("%s",x)typedef long long ll;typedef unsigned long long ull;typedef unsigned int U;#define ms(x) memset((x),0,sizeof(x))const long long int mod = 1e9 + 7;#define Mod 1000000000#define sq(x) (x)*(x)#define eps 1e-3typedef pair
pii;#define pi acos(-1.0)//const int N = 1005;#define REP(i,n) for(int i=0;i<(n);i++)typedef pair
pii;inline ll rd() { ll x = 0; char c = getchar(); bool f = false; while (!isdigit(c)) { if (c == '-') f = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f ? -x : x;}ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b);}ll sqr(ll x) { return x * x; }/*ll ans;ll exgcd(ll a, ll b, ll &x, ll &y) { if (!b) { x = 1; y = 0; return a; } ans = exgcd(b, a%b, x, y); ll t = x; x = y; y = t - a / b * y; return ans;}*/int n;int a[maxn];struct node { int st;// 端点 int dx;// 差值 int cnt;// 计数 int fg;}td[maxn];map
mp;int main() { //ios::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; td[a[i]].cnt++; if (td[a[i]].cnt == 1) { td[a[i]].st = i; td[a[i]].fg = 1; } else { if (td[a[i]].cnt == 2) { td[a[i]].dx = i - td[a[i]].st; td[a[i]].st = i; } else { if (td[a[i]].dx != i - td[a[i]].st) { td[a[i]].fg = 0; } else { td[a[i]].dx = i - td[a[i]].st; td[a[i]].st = i; } } } } sort(a + 1, a + 1 + n); int tot = unique(a + 1, a + 1 + n) - a - 1; bool fg = 0; int ct = 0; for (int i = 1; i <= tot; i++) { if (td[a[i]].fg == 1) { ct++; } } if (ct == 0) { cout << 0 << endl; return 0; } cout << ct << endl; for (int i = 1; i <= tot; i++) { // cout << a[i] << ' ' << td[a[i]].fg << ' ' << td[a[i]].dx << endl; if (td[a[i]].cnt == 1) { cout << a[i] << ' ' << 0 << endl; } else if (td[a[i]].cnt > 1 && td[a[i]].fg == 1) { cout << a[i] << ' ' << td[a[i]].dx << endl; } } return 0;}

 

转载于:https://www.cnblogs.com/zxyqzy/p/10200353.html

你可能感兴趣的文章
Jquery 以及AngularJS 中 Get/Post 传参笔记
查看>>
Android入门篇(二)布局文件 容器②
查看>>
如何在Kubernetes中管理有状态应用
查看>>
一个基于react的图片裁剪组件
查看>>
PWA介绍及快速上手搭建一个PWA应用
查看>>
js数组用法
查看>>
Dubbo学习笔记
查看>>
基于 Redis驱动的 Laravel 事件广播
查看>>
NPM酷库040:jschardet,识别数据编码
查看>>
图书管理系统【用户、购买、订单模块、添加权限】
查看>>
JavaScript30秒, 从入门到放弃之Array(六)
查看>>
RabbitMQ的安装和使用
查看>>
WebAssembly起步
查看>>
基于CentOS搭建Hexo博客--设置NexT主题及个性化定制
查看>>
百度移动端首页秒开学习
查看>>
【304天】每日项目总结系列042(2017.12.06)
查看>>
数人云|给还在犹豫选择的你,微服务架构与整体架构的各自优势
查看>>
ES6之数值的扩展
查看>>
算法之路(1) -- two sum
查看>>
JavaScript Event loop 事件循环
查看>>