Pagini recente » Cod sursa (job #1209658) | Cod sursa (job #3272552) | Cod sursa (job #1478013) | Cod sursa (job #2910630) | Cod sursa (job #1709505)
#include <fstream>
using namespace std;
ifstream f ("pq.in");
ofstream g ("pq.out");
int x,y,i,j,l,n,q,v[100001],co,cost,t;
int main()
{
f>>n>>q;
for(i=1;i<=n;++i) f>>v[i];
for(j=1;j<=q;++j)
{
f>>x>>y;
cost=0;
for(i=x;i<y;++i)
{
for(t=i+1;t<=y;++t)
{
if(v[i]==v[t]) {co=t-i; if(co>cost) cost=co; break;}
}
}
if(!cost) g<<-1<<"\n";
else g<<cost<<"\n";
}
return 0;
}