Pagini recente » Cod sursa (job #2754973) | Cod sursa (job #2374872) | Cod sursa (job #2781790) | Cod sursa (job #2267222) | Cod sursa (job #3282959)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
int n, L, U;
unsigned int a[(1 << 20) + 3];
///returneaza nr de secvente care au cel mult x nr distincte
long long F(int x)
{
unordered_map<unsigned int, int>fr;
int i, j, cnt = 0;
long long nrsecv = 0;
i = 1;
for(j = 1; j <= n; j++)
{
fr[a[j]]++;
if(fr[a[j]] == 1) cnt++;
while(cnt > x)
{
fr[a[i]]--;
if(fr[a[i]] == 0) cnt--;
i++;
}
nrsecv += (j - i + 1);
}
return nrsecv;
}
int main()
{
int i;
fin >> n >> L >> U;
for(i = 1; i <= n; i++)
fin >> a[i];
fout << F(U) - F(L - 1);
return 0;
}