Codeforces Round #204 (Div. 2): B

时间:2023-03-08 22:35:21

很简单的一个题;

只需要将他们排一下序,然后判断一下就可以了!

代码:

 #include<cstdio>
#include<algorithm>
#define maxn 100005
using namespace std; int n,x;
int a[maxn][],cot;
struct node
{
int v,id;
bool operator<(node const &t)const
{
if(v==t.v)return id<t.id;
return v<t.v;
}
} no[maxn]; int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&x);
no[i].v=x;
no[i].id=i;
}
sort(no+,no+n+);
for(int i=; i<=n;)
{
int t=no[i].v;
if(no[i+].v!=t)
{
a[cot][]=no[i].v;
a[cot][]=;
cot++;
i++;
}
else
{
int d=no[i+].id-no[i].id;
while()
{
i++;
if(no[i+].v!=t)
{
a[cot][]=t;
a[cot][]=d;
cot++;
i++;
break;
}
if(no[i+].id-no[i].id!=d)
{
while()
{
i++;
if(no[i+].v!=no[i].v)
{
i++;
break;
}
}
break;
}
}
}
}
printf("%d\n",cot);
for(int i=;i<cot;i++)
printf("%d %d\n",a[i][],a[i][]);
return ;
}