Pagini recente » Cod sursa (job #2881635) | Cod sursa (job #732575) | Cod sursa (job #3124460) | Cod sursa (job #3257799) | Cod sursa (job #2269536)
#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];
int x=secv(U)-secv(L-1);
out<<x<<"\n";
out.close();
in.close();
return 0;
}