Cod sursa(job #1709662)

Utilizator UAIC_TheFormerOneUAIC TheFormerOne UAIC_TheFormerOne Data 28 mai 2016 13:17:48
Problema Pq Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.66 kb
#include<vector>
#include<fstream>

using namespace std;




int main(){
	int a[100001];
	int v[100001];
	int n, i, j,q;
	ifstream fin("pq.in");
	ofstream fout("pq.out");

	fin >> n>>q;

	for (i = 1; i <= n; ++i)
		fin >> a[i];

	for (i = 1; i < n; ++i)
	{
		bool ok = 0;
		for (j = i + 1; j <= n && !ok; ++j)
			if (a[i] == a[j])
			{
				v[i] = j; ok = 1;
			}
		
	}

	int L, R,max,u,vr;
	while (q){
		fin >> L >> R;
		max = -1;
		bool ok = 1;
		for (u = L; u < R && ok;++u)
		{	
			vr = v[u];
			if (max < vr - u && vr <=R)
				max = vr-u;
			if (max + u + 1 >R) ok = 0;
		}
		fout << max << "\n";
		q--;
		}
	return 0;
}