Pagini recente » Cod sursa (job #2536544) | Cod sursa (job #928981) | Cod sursa (job #1571790) | Cod sursa (job #1557405) | Cod sursa (job #2759069)
/*
utilizare unordered_map
*/
#include <bits/stdc++.h>
using namespace std;
unsigned a[1100000];
int n, L, U;
long long Rezolva(unsigned t)
{
unordered_map <unsigned, int> h;
long long sol = 0, last = 1;
for(int i = 1; i <= n; i++)
{
h[a[i]]++;
while(h.size() > t)
{
h[a[last]]--;
if(h[a[last]]==0)
h.erase(a[last]);
last++;
}
sol += (i - last + 1);
}
return sol;
}
int main()
{
ifstream fin("secv5.in");
ofstream fout("secv5.out");
fin >> n >> L >> U;
for(int i = 1; i <= n; i++)
fin >> a[i];
fout << (Rezolva(U) - Rezolva(L - 1)) << "\n";
fin.close();
fout.close();
return 0;
}