Cod sursa(job #1709668)

Utilizator flawlessUCV Turcu Abu-ras Albastroiu flawless Data 28 mai 2016 13:19:57
Problema Pq Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.8 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include<stdlib.h>
using namespace std;
int n,q,el,l,r,v[10000],ind,j,max1;
long long count2;
int i;
//FILE *fin = fopen("carte2.in", "r");
//FILE *fout = fopen("carte2.out", "w");
int main(){
ifstream f("pq.in");
ofstream g("pq.out");
f>>n>>q;
//  fclose(fin);
//  fclose(fout);
for(i=1;i<=n;i++)
{
f>>v[i];
}
for(i=1;i<=q;i++)
    {
     f>>l>>r;
     ind=l;
     max1=-1;
     while(ind<=r)
     {
     el=v[ind];
     for(j=ind;j<=r;j++)
            if (v[j]==el)
            {
                if(j-ind>max1)
                    max1=j-ind;
                ind=j;
            }
       ind++;
     }
     if(max1==0)
        g<<-1<<'\n';
     else
        g<<max1<<'\n';
    }
}