Pagini recente » Cod sursa (job #1199864) | Cod sursa (job #1148827) | Cod sursa (job #1469912) | Cod sursa (job #2904404) | Cod sursa (job #2607218)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
const int MOD = 230017;
unsigned int n,l,u,x,nrl,nru,lastl=1,lastu=1;
unsigned long long sol;
vector < pair<int,int> > Hashl[MOD];
map <int,int> Ml,Mu;
queue <unsigned int> Ql,Qu;
void GetHash(int type, unsigned int value)
{
int l=value%MOD;
bool ok=0;
vector < pair<int,int> > :: iterator it;
for(it=Hashl[l].begin();it!=Hashl[l].end();it++)
{
if(((*it).first)==value)
{
if(type==1)
{
ok=1;
return;
}
}
}
}
int main()
{
fin>>n>>l>>u;
for(unsigned int i=1;i<=n;i++)
{
fin>>x;
Ql.push(x);
Qu.push(x);
GetHash(1,x);
if(!Ml[x])
nrl++;
if(!Mu[x])
nru++;
Mu[x]++;
Ml[x]++;
while(!Qu.empty() && nru>u)
{
int elm=Qu.front();
Qu.pop();
Mu[elm]--;
lastu++;
if(!Mu[elm])
nru--;
}
while(!Ql.empty())
{
int elm=Ql.front();
if(nrl>l)
{
Ql.pop();
Ml[elm]--;
lastl++;
if(!Ml[elm])
nrl--;
}
else
{
if(Ml[elm]>1)
{
lastl++;
Ml[elm]--;
Ql.pop();
}
else
break;
}
}
if(nrl>=l && nru<=u)
sol+=lastl-lastu+1;
}
fout<<sol<<'\n';
}