Pagini recente » Cod sursa (job #895661) | Cod sursa (job #854375) | Cod sursa (job #2314831) | Cod sursa (job #1055553) | Cod sursa (job #2269532)
#include <bits/stdc++.h>
using namespace std;
const int nmax=1048600;
int N,L,U,a[nmax];
queue <int> q;
unordered_map <int,int> M;
int secv(int x)
{int i,k=0,fin=0;
for (i=1;i<=N;i++)
{
q.push(a[i]);
M[a[i]]++;
if (M[a[i]]==1)k++;
while (k>x)
{
if (M[q.front()]==1)k--;
M[q.front()]--;
q.pop();
}
fin+=q.size();
}
while (!q.empty())
{
M[q.front()]--;
q.pop();
}
return fin;
}
int main()
{int i;
ifstream in("secv5.in");
ofstream out("secv5.out");
in>>N>>L>>U;
for (i=1;i<=N;i++)
{
in>>a[i];
}
out<<secv(U)-secv(L-1)<<"\n";
}