Cod sursa(job #3316578)

Utilizator popescu_georgePopescu George popescu_george Data 19 octombrie 2025 12:10:18
Problema Secventa 5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.15 kb
#include<fstream>
using namespace std;
ifstream cin("secv5.in");
ofstream cout("secv5.out");
const int Z=4096,M=666013,N=1048576;
struct W {
    unsigned n;
    int f;
};
W z[N];
int l,n,p=Z,u,w,x[N],y[M];
unsigned v[N];
char s[Z];
inline char A()
{
    if(p==Z)
        cin.read(s,Z),p=0;
    return s[p++];
}
unsigned B()
{
    unsigned n=0;
    for(char c=A();c>47;n=c-48+n*10,c=A());
    return n;
}
int C(unsigned q)
{
    int l=q%M,i=y[l],r=0;
    for(;i!=-1&&z[i].n!=q;i=x[i]);
    i==-1?z[w].n=q,z[w].f=1,x[w]=y[l],y[l]=w++,r=1:++z[i].f;
    return r;
}
int D(unsigned q)
{
    int l=q%M,b=y[l],i=x[b],r=0;
    if(z[b].n==q) {
        if(!--z[b].f)
            y[l]=x[b],r=1;
    } else {
        for(;i!=-1&&z[i].n!=q;b=i,i=x[i]);
        if(i!=-1&&!--z[i].f)
            x[b]=x[i],r=1;
    }
    return r;
}
long long E(int q)
{
	w=0;
    for(int i=0;i<M;y[i++]=-1);
    for(int i=0;i<N;x[i]=-1,z[i++].f=0);
	long long m=0;
	for(int d=0,e=0,f=0;f<n;m+=++f-e)
		for(d+=C(v[f]);e<=f&&d>q;d-=D(v[e++]));
	return m;
}
int main()
{
	n=B(),l=B(),u=B();
	for(int i=0;i<n;v[i++]=B());
	return cout<<E(u)-E(l-1),0;
}