Pagini recente » Cod sursa (job #25298) | Cod sursa (job #317772) | Borderou de evaluare (job #1569031) | Cod sursa (job #3200489) | Cod sursa (job #2607220)
#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)
{
((*it).second)++;
ok=1;
return;
}
else if(type==2)
{
if(((*it).second)>1)
((*it).second)--;
else
Hashl[l].erase(it);
return;
}
}
}
if(type==1 && !ok)
Hashl[l].push_back(make_pair(value,1));
}
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();
GetHash(2,elm);
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';
}