Pagini recente » Cod sursa (job #410598) | Cod sursa (job #1351361) | Cod sursa (job #2614983) | Cod sursa (job #1163851) | Cod sursa (job #594922)
Cod sursa(job #594922)
#include <cstdio>
#include <vector>
using namespace std;
typedef pair<unsigned int,unsigned int> puu;
vector <unsigned int> hl[200003],hr[200003];
unsigned int v[1048576],n,p,q,cnt,l=0,r=0,sol;
puu z;
puu prev_exist_l(unsigned int x)
{
unsigned int a=x%200003,i,aux=0,ind;
for (i=0;i<hl[a].size();++i)
if (hl[a][i]==x)
{
++aux;
ind=i;
}
return make_pair(aux,ind);
}
puu prev_exist_r(unsigned int x)
{
unsigned int a=x%200003,i,aux=0,ind;
for (i=0;i<hr[a].size();++i)
if (hr[a][i]==x)
{
++aux;
ind=i;
}
return make_pair(aux,ind);
}
unsigned int part1(unsigned int i)
{
unsigned int a,b;
for (;i<n&&cnt<p;++i)
{
a=v[i]%200003;
hl[a].push_back(v[i]);
hr[a].push_back(v[i]);
z=prev_exist_l(v[i]);
if (z.first==1)
++cnt;
}
b=v[r]%200003;
z=prev_exist_r(v[r]);
while (z.first>1&&r<i)
{
hr[b][z.second]=hr[b][hr[b].size()-1];
hr[b].pop_back();
++r;
b=v[r];
z=prev_exist_r(v[r]);
}
sol+=r+1;
return i;
}
unsigned int part2(unsigned int i)
{
unsigned int a,b;
for (;i<n&&cnt<q;++i)
{
a=v[i]%200003;
hl[a].push_back(v[i]);
hr[a].push_back(v[i]);
z=prev_exist_r(v[i]);
if (z.first==1)
{
z=prev_exist_l(v[i]);
if (z.first==1)
++cnt;
b=v[r]%200003;
z=prev_exist_r(v[r]);
while (z.first>1&&r<i-1)
{
hr[b][z.second]=hr[b][hr[b].size()-1];
hr[b].pop_back();
++r;
b=v[r]%200003;
z=prev_exist_r(v[r]);
}
hr[b][z.second]=hr[b][hr[b].size()-1];
hr[b].pop_back();
++r;
}
b=v[r]%200003;
z=prev_exist_r(v[r]);
while (z.first>1&&r<i)
{
hr[b][z.second]=hr[b][hr[b].size()-1];
hr[b].pop_back();
++r;
b=v[r]%200003;
z=prev_exist_r(v[r]);
}
sol+=r+1;
}
return i;
}
void part3(unsigned int i)
{
unsigned int a,b;
for (;i<n;++i)
{
a=v[i]%200003;
hl[a].push_back(v[i]);
hr[a].push_back(v[i]);
z=prev_exist_r(v[i]);
if (z.first==1)
{
b=v[r]%200003;
z=prev_exist_r(v[r]);
while (z.first>1&&r<i-1)
{
hr[b][z.second]=hr[b][hr[b].size()-1];
hr[b].pop_back();
++r;
b=v[r]%200003;
z=prev_exist_r(v[r]);
}
hr[b][z.second]=hr[b][hr[b].size()-1];
hr[b].pop_back();
++r;
z=prev_exist_l(v[i]);
if (z.first==1)
{
b=v[l]%200003;
z=prev_exist_r(v[l]);
while (z.first>1&&l<i-1)
{
hl[b][z.second]=hl[b][hl[b].size()-1];
hl[b].pop_back();
++l;
b=v[l]%200003;
z=prev_exist_r(v[l]);
}
hl[b][z.second]=hl[b][hl[b].size()-1];
hl[b].pop_back();
++l;
z=prev_exist_l(v[i]);
}
}
b=v[r]%200003;
z=prev_exist_r(v[r]);
while (z.first>1&&r<i)
{
hr[b][z.second]=hr[b][hr[b].size()-1];
hr[b].pop_back();
++r;
b=v[r]%200003;
z=prev_exist_r(v[r]);
}
sol+=r-l+1;
}
}
int main()
{
unsigned int i;
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
scanf("%u %u %u\n",&n,&p,&q);
for (i=0;i<n;++i)
scanf("%d",&v[i]);
part3(part2(part1(0)));
printf("%u\n",sol);
return 0;
}