Pagini recente » Cod sursa (job #812425) | Cod sursa (job #2488987) | Cod sursa (job #2538232) | Cod sursa (job #502148) | Cod sursa (job #2038993)
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[1024 * 1024 + 20], n, L, U;
///cate secvente au cel mult k valori distincte
unsigned long long NrSecvente(unsigned int K)
{
unordered_map <unsigned, int> m;
long long cnt = 0, j = 1;
for(int i = 1; i <= n; i++)
{
m[a[i]]++;
while(m.size() > K)
{
m[a[j]]--;
if(m[a[j]]==0)
m.erase(a[j]);
j++;
}
cnt += (i - j + 1);
}
return cnt;
}
int main()
{
ifstream fin("secv5.in");
fin >> n >> L >> U;
for(int i = 1; i <= n; i++)
fin >> a[i];
ofstream fout("secv5.out");
fout << NrSecvente(U) - NrSecvente(L - 1) << "\n";
return 0;
}