This b is not difficult ... It's mostly test instructions and details.
Test instructions is to find the most occurrences of the number of the left and right end of the value,, as many words to find the smallest interval,,, the same length of the left to find ...
Change a little bit messy,,,, slowly change well,,,,,
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace Std;
struct node
{
int c,b;
}A[100001];
int cmp (const void *a,const void *b)
{
struct node *q= (node*) A;
struct node *w= (node*) b;
if (q->c!=w->c) return q->c-w->c;
else return q->b-w->b;
}
int main ()
{
int m;
scanf ("%d", &m);
int i;
for (i=0;i<m;i++)
{
scanf ("%d", &a[i].c);
A[i].b=i;
}
Qsort (A,m,sizeof (a[0]), CMP);
for (i=0;i<10;i++) printf ("%d*\n", a[i].b);
int Ans=1;
int ans1=a[0].b;
int ans2=a[0].b;
int left=a[0].b,right=a[0].b;
printf ("%d%d**\n", ans1,ans2);
int w=1;
for (i=1;i<m;i++)
{
if (A[I].C==A[I-1].C)
{
w++;
if (i==m-1)
{
right=a[i].b;
if (W>ans) {ans=w; ans1=right; ans2=left;}
if (W==ans)
{
if (RIGHT-LEFT<ANS1-ANS2) ans1=right,ans2=left;
}
}
}
Else
{
printf ("%d**\n", I);
printf ("%d**\n", W);
right=a[i-1].b;
if (W>ans) {ans=w; ans1=right; ans2=left;}
printf ("%d**%d\n", ans1,ans2);
if (W==ans)
{
if (RIGHT-LEFT<ANS1-ANS2) ans1=right,ans2=left;
else if (RIGHT-LEFT==ANS1-ANS2)
{
if (ans2>left) ans1=right,ans2=left;
}
}
left=a[i].b;
W=1;
}
}
printf ("%d%d\n", ans2+1,ans1+1);
return 0;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 558B AMR and the Large Array