SEARCH1 - Other search problem
Tác giả: flashmt
Ngôn ngữ: C++
#include <iostream>
#include <algorithm>
using namespace std;
int cntA[100100], c[100100], cnt[100100], inB[100100];
int main()
{
int x, m, p, n, ans = 0;
cin >> n >> m >> p;
int nn = 0;
while (n--) cin >> x, nn += !cntA[x], cntA[x]++;
n = nn;
while (m--) cin >> x, inB[x] = 1;
for (int i = 0, j = 0, distinct = 0; i < p; i++)
{
cin >> c[i];
if (inB[c[i]])
{
while (j < i) cnt[c[j++]]--;
distinct = 0;
j = i + 1;
}
else
{
if (++cnt[c[i]] == cntA[c[i]]) ++distinct;
if (distinct == n) ans = max(ans, i - j + 1);
}
}
cout << ans << endl;
}