Pagini recente » Cod sursa (job #3003289) | Cod sursa (job #1629002) | Cod sursa (job #1854866) | Cod sursa (job #2421363) | Cod sursa (job #210977)
Cod sursa(job #210977)
#include<cstdio>
#include<list>
using namespace std;
const int M=196613;
const int N=(1<<20);
list<unsigned int> h1[M],h2[M];
unsigned int v[N],n,st,dr,nr[N],nd,w[N];
bool exista(unsigned int x){
unsigned int r=x%M;
for(list<unsigned int>::iterator it=h1[r].begin() ; it!=h1[r].end() ; ++it)
if(*it==x)
return true;
return false;
}
unsigned int pozitie(unsigned int x){
unsigned int r=x%M;
list<unsigned int>::iterator it1,it2;
for(it1=h1[r].begin(),it2=h2[r].begin() ; it1!=h1[r].end() ; ++it1,++it2)
if(*it1==x)
return *it2;
return 0;
}
void citire(){
scanf("%d%d%d",&n,&st,&dr);
for(unsigned int i=0;i<n;++i){
scanf("%u",&v[i]);
if(!exista(v[i])){
h1[v[i]%M].push_back(v[i]);
h2[v[i]%M].push_back(nd++);
}
}
}
/*
unsigned int val(unsigned int i){
list<unsigned int>::iterator it1,it2;
for(unsigned int j=0;j<M;++j)
for(it1=h1[j].begin(),it2=h2[j].begin() ; it1!=h1[j].end() ; ++it1,++it2)
if(*it2==i)
return *it1;
return 0;
}
void proba(){
for(int i=0;i<n;++i)
printf("%d apare pe pozitia %d\n",v[i],w[i]);
}
*/
long long calcul(unsigned int dr){
unsigned int i,j,nrs=1,p;
long long rez=0;
++nr[w[0]];
for(i=1,j=0;i<n;++i)
{
p=w[i];
++nr[p];
if(nr[p]==1)
++nrs;
if(nrs==1+dr){
while(nr[w[j]]>1)
--nr[w[j++]];
--nr[w[j++]];
--nrs;
}
rez+=(long long)i-j+1;
}
return rez;
}
void calcul_w(){
for(unsigned int i=0;i<n;++i)
w[i]=pozitie(v[i]);
}
int main(){
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
citire();
//printf("%d\n",numarul(196613));
calcul_w();
//proba();
long long x=calcul(dr);
memset(nr,0,N*sizeof(int));
printf("%lld\n",x-calcul(st-1));
return 0;
}