Pagini recente » Cod sursa (job #1435206) | Cod sursa (job #2454048) | Cod sursa (job #2625271) | Cod sursa (job #2190926) | Cod sursa (job #917949)
Cod sursa(job #917949)
#include<fstream>
#include<algorithm>
#define mod 666013
#define nmax 1<<20+3
using namespace std;
unsigned int i,j,n,m,b[nmax],l,u,pozu[nmax],pozl[nmax],nr,rez=0;
unsigned int apl[nmax],nrl=0,nru=0,apu[nmax];
struct ordine
{
unsigned long long int x;
unsigned int poz;
};
ordine a[nmax];
bool cmp(ordine a,ordine b)
{
if(a.x==b.x)
return a.poz<b.poz;
return a.x<b.x;
}
int main()
{
ifstream f("secv5.in");
ofstream g("secv5.out");
f>>n>>l>>u;
--l;
for(i=1;i<=n;++i)
f>>a[i].x,a[i].poz=i;
sort(a+1,a+n+1,cmp);
for(i=1;i<=n;++i)
{
if(a[i].x!=a[i-1].x)
++nr;
b[a[i].poz]=nr;
}
apl[b[1]]=apu[b[1]]=1;
pozu[1]=pozl[1]=1;
nrl=nru=1;
for(i=2;i<=n;++i)
{
++apl[b[i]];
++apu[b[i]];
if(apl[b[i]]==1)
++nrl;
j=pozl[i-1];
while(nrl>l)
{
--apl[b[j]];
if(!apl[b[j]])
--nrl;
++j;
}
pozl[i]=j;
if(apu[b[i]]==1)
++nru;
j=pozu[i-1];
while(nru>u)
{
--apu[b[j]];
if(!apu[b[j]])
--nru;
++j;
}
pozu[i]=j;
rez+=(i-pozu[i]+1)-(i-pozl[i]+1);
}
if(!rez)
g<<1<<"\n";
else
g<<rez<<"\n";
return 0;
}