Pagini recente » Cod sursa (job #335704) | Cod sursa (job #990992) | Cod sursa (job #922631) | Cod sursa (job #1727222) | Cod sursa (job #1766281)
#include <iostream>
#include<fstream>
#include<vector>
using namespace std;
typedef unsigned int uint;
const uint mod=99017;
vector< pair<uint,int> > h[mod+5];
uint x,key;
int v[(1<<20)+5],n,p,u,i,i1,i2,j,neww,ap1[(1<<20)+5],ap2[(1<<20)+5],dist1,dist2;
long long tot;
bool moved;
void ins()
{
key=x%mod;
for(j=0;j<h[key].size();j++)
if(h[key][j].first==x)
{
v[i]=h[key][j].second;
return;
}
neww++;
v[i]=neww;
h[key].push_back(make_pair(x,neww));
}
int main()
{
ifstream f("secv5.in");
ofstream g("secv5.out");
f>>n>>p>>u;
for(i=1;i<=n;i++)
{
f>>x;
ins();
}
i1=0;i2=0;
for(i=1;i<=n;i++)
{
if(ap1[v[i]]==0)
dist1++;
if(ap2[v[i]]==0)
dist2++;
ap1[v[i]]++;
ap2[v[i]]++;
while(dist1>=p)
{
if(ap1[v[i1]]==1) dist1--;
ap1[v[i1]]--;
i1++;
}
while(dist2>=u)
{
if(ap2[v[i2]]==1) dist2--;
ap2[v[i2]]--;
i2++;
}
if(i1!=0)tot+=i1-i2+1;
}
g<<tot;
return 0;
}