Pagini recente » Cod sursa (job #2977292) | Cod sursa (job #976642) | Cod sursa (job #2291632) | Cod sursa (job #48422) | Cod sursa (job #906060)
Cod sursa(job #906060)
#include<cstdio>
#include<fstream>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#define M 666013
#define NMax (1<<20)+5
using namespace std;
unsigned v[NMax];
int n;
vector<pair<unsigned,int> > a[M];
vector<pair<unsigned,int> >::iterator find (unsigned x)
{
vector<pair<unsigned,int> >::iterator it;
for (it=a[x%M].begin(); it!=a[x%M].end(); ++it)
if ((it->first)==x)
return it;
return a[x%M].end();
}
void hash ()
{
int i;
for (i=1; i<=n; i++)
if (find(v[i])==a[v[i]%M].end())
a[v[i]%M].push_back(make_pair(v[i],0));
}
void reset ()
{
int i;
vector<pair<unsigned,int> >::iterator it;
for (i=1; i<=n; i++)
{
it=find(v[i]);
it->second=0;
}
}
long long sol (int x)
{
if (!x) return 0;
int nr=1,st=1,i;
long long sum=1,aux;
vector<pair<unsigned,int> >::iterator it;
it=find(v[1]);
it->second=1;
for (i=2; i<=n; i++)
{
it=find(v[i]);
if (it->second==0)
nr++;
it->second++;
while (nr>x)
{
it=find(v[st]);
if (it->second==1)
nr--;
it->second--;
st++;
}
aux=(long long)(i-st+1);
sum+=aux;
}
return sum;
}
int main ()
{
int l,u,i,j,lg;
long long r1,r2;
ifstream f("secv5.in");
freopen("secv5.out","w",stdout);
f>>n>>l>>u;
for (i=1; i<=n; i++)
{
string s;
getline(f,s);
istringstream iss(s);
iss>>v[i];
}
hash();
r1=sol(u);
reset();
r2=sol(l-1);
printf("%lld\n",r1-r2);
return 0;
}