Pagini recente » Cod sursa (job #567436) | Cod sursa (job #1313582) | Cod sursa (job #1408767) | Cod sursa (job #1868982) | Cod sursa (job #791477)
Cod sursa(job #791477)
#include<fstream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
int n,L,U,nmax;
vector <pair <unsigned int,int> > A;
int v[1050000];
inline void Citire()
{
int i,ns,poz;
unsigned int aux;
char s[20];
ifstream fin("secv5.in");
fin>>n>>L>>U;
fin.getline(s,20);
for(i=1;i<=n;i++)
{
fin.getline(s,20);
ns=strlen(s);
poz=0;
aux=0;
while(poz<ns)
aux=aux*10+s[poz++]-'0';
A.push_back(make_pair(aux,i));
}
fin.close();
}
inline void Normalizare()
{
int i,norm=0;
sort(A.begin(),A.end());
v[A[0].second]=++norm;
for(i=1;i<n;i++)
{
if(A[i].first==A[i-1].first)
v[A[i].second]=norm;
else
v[A[i].second]=++norm;
}
nmax=norm;
}
inline long long Nr(int size)
{
long long sol=0;
int st=1,dr=1,now=0;
vector <int> viz;
viz.resize(nmax+1,0);
while(dr<=n)
{
if(viz[v[dr]]==0)
now++;
viz[v[dr]]++;
while(now>size)
{
viz[v[st]]--;
if(viz[v[st]]==0)
now--;
st++;
}
sol+=(long long)(dr-st+1);
dr++;
}
return sol;
}
inline void Afisare()
{
long long sol=Nr(U)-Nr(L-1);
ofstream fout("secv5.out");
fout<<sol<<"\n";
fout.close();
}
int main()
{
Citire();
Normalizare();
Afisare();
return 0;
}