Pagini recente » Cod sursa (job #2364873) | Cod sursa (job #18565) | Cod sursa (job #2161430) | Cod sursa (job #2667245) | Cod sursa (job #2141281)
#include <fstream>
#include <iostream>
#include <unordered_map>
#define MAX 1<<20 + 6
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
unsigned a[MAX],n,L,U;
unsigned x;
long long NrSecvente(int K)
{
unordered_map<unsigned,int> M;
long long cnt = 0;
int i,j;
i = 1;
for(j=1; j<=n; ++j)
{
++M[a[j]];
while(M.size() > K)
{
x = a[i];
++i;
--M[x];
if(M[x] == 0) M.erase(x);
}
cnt +=j-i+1;
}
return cnt;
}
int main()
{
fin>>n>>L>>U;
for(int i=1; i<=n; ++i)
fin>>a[i];
fout<<NrSecvente(U) - NrSecvente(L-1);
return 0;
}