Pagini recente » Cod sursa (job #1748860) | Cod sursa (job #2368259) | Istoria paginii utilizator/corina.condurachi | Cod sursa (job #1549632) | Cod sursa (job #2149807)
#include<fstream>
#include<vector>
#define M 66013
#include<algorithm>
#include<unordered_map>
#include<iostream>
#define pb push_back
#include<cstdio>
#define x first
#define y second
using namespace std;
ofstream fout("secv5.out");
long long n,a[(1<<20)+5],p,f,val,poz,st,dr,mij,r1,r2,rez,l,u;
unordered_map<long long,int>mp;
long long ve(int z)
{
mp.clear();
long long rez=0;
int j=1;
for(int i=1;i<=n;i++)
{
mp[a[i]]++;
while(mp.size()>z)
{
mp[a[j]]--;
if(mp[a[j]]==0)
mp.erase(a[j]);
j++;
}
rez+=(i-j+1);
}
return rez;
}
FILE* fin=fopen("secv5.in","r");
const unsigned maxb=30000192;
char buf[maxb];
unsigned ptr;
inline unsigned getint()
{
unsigned nr=0;
while('0'>buf[ptr]||buf[ptr]>'9')
if(++ptr>=maxb)
fread(buf,maxb,1,fin),ptr=0;
while('0'<=buf[ptr]&&buf[ptr]<='9')
{
nr=nr*10+buf[ptr]-'0';
if(++ptr>=maxb)
fread(buf,maxb,1,fin),ptr=0;
}
return nr;
}
int main()
{
n=getint();
l=getint();
u=getint();
for(int i=1;i<=n;i++)
a[i]=getint();
fout<<ve(u)-ve(l-1);
}