Cod sursa(job #1709497)
| Utilizator | Data | 28 mai 2016 12:36:07 | |
|---|---|---|---|
| Problema | Pq | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest | Marime | 0.65 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("pq.in");
ofstream fout("pq.out");
const int NMax = 1e5 + 5;
int v[NMax];
int last[NMax];
int main(){
int n, m, x, a, b;
fin >> n >> m;
for(int i = 1; i <= n; i++){
fin >> v[i];
if(last[v[i]] != 0){
v[last[v[i]]] = i - last[v[i]];
}
last[v[i]] = i;
v[i] = 0;
}
while(m--){
fin >> a >> b;
x = -1;
for(int i = a; i < b; i++){
if(v[i] != 0 && i + v[i] <= b){
x = max(x, v[i]);
}
}
fout << x << "\n";
}
return 0;
}
