Pagini recente » Cod sursa (job #2521858) | Istoria paginii utilizator/oltwister | Profil Catalin | Profil Diana975 | Cod sursa (job #2013656)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
const int Pmax=123457;
const int nmax=(1<<21);
vector<pair<unsigned int ,int> >L[Pmax];
int n,stg,drp,nrdist,aux;
unsigned int a[nmax];
inline void Read()
{
fin>>n>>stg>>drp;
aux=stg;
for(int i=1;i<=n;i++)
fin>>a[i];
}
inline void Push(unsigned int x)
{
bool ok=true;
int r=x%Pmax,k;
k=L[r].size();
for(int i=0;i<k && ok;i++)
if(L[r][i].first==x)
{
L[r][i].second++;
ok=false;
}
if(ok)
{
nrdist++;
L[r].push_back({x,1});
}
}
inline void POP(unsigned int x)
{
bool ok=true;
int r,k;
r=x%Pmax;
k=L[r].size();
for( int i=0;i<k && ok;i++)
if(L[r][i].first==x)
{
L[r][i].second--;
ok=false;
if(!L[r][i].second)
{
nrdist--;
swap(L[r][i].first,L[r][k-1].first);
swap(L[r][i].second,L[r][k-1].second);
L[r].pop_back();
}
}
}
inline long long Solve(int k)
{
long long sol=0;
int j=1;
nrdist=0;
for(int i=1;i<=Pmax;i++)
L[i].clear();
for(int i=1;i<=n;i++)
{
Push(a[i]);
while(nrdist>k)
{
POP(a[j]);
j++;
}
sol+=(1LL*(i-j+1));
}
return sol;
}
int main()
{
Read();
int x=Solve(drp);
int y=Solve(aux-1);
fout<<(x-y)<<"\n";
fin.close();
fout.close();
return 0;
}