Pagini recente » Borderou de evaluare (job #407443) | Borderou de evaluare (job #2026805) | Cod sursa (job #2038989)
#include <fstream>
#include <unordered_map>
#define NMAX 1024*1024 + 5
using namespace std;
ifstream fin ("secv5.in");
ofstream fout("secv5.out");
unsigned a[NMAX], n, L, U;
/// cate secvente au cel mult k valori distincte
long long NrSecvente(int k)
{
unordered_map <unsigned, int> M;
int i, j, x;
long long cnt = 0;
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);
/// adaug cele j-i+1 secv care se termina cu a[j]
}
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;
}