Pagini recente » Cod sursa (job #406736) | Cod sursa (job #2750749) | Cod sursa (job #2144263) | Cod sursa (job #1696328) | Cod sursa (job #1709444)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int A[100001];
int poz[100001];
int last[100001];
int main()
{
int N, Q;
ifstream f("pq.in");
ofstream g("pq.out");
f >> N >> Q;
for (int i = 1; i <= N; ++i) {
f >> A[i];
if (poz[A[i]] == 0) {
last[i] = -1;
poz[A[i]] = i;
continue;
}
last[i] = poz[A[i]];
poz[A[i]] = i;
}
for (; Q > 0; --Q) {
int x, y;
f >> x >> y;
int max = -1;
for (int i = x + 1; i <= y; ++i) {
if (last[i] >= x) {
int max_p = i - last[i];
max = max ^ ((max ^ max_p) & -(max < max_p));
}
}
g << max << '\n';
}
return 0;
}