Cod sursa(job #653167)
#include<stdio.h>
#include<vector>
#define maxn (1<<20)+5
#define MOD ((1<<19)-1)
#define pb push_back
#define mp make_pair
#define file_size 11000000
using namespace std;
FILE*f=fopen("secv5.in","r");
FILE*g=fopen("secv5.out","w");
int n,l,u,i,nrst,nrdr,ch;
unsigned int v[maxn];
long long sol;
vector< pair<unsigned int,int> >H1[MOD+5],H2[MOD+5];
char buff[file_size+5];
inline unsigned int next () {
unsigned int r = 0;
while ( buff[ch] >= '0' && buff[ch] <= '9' ){
r = r * 10 + buff[ch] - '0';
++ch;
}
++ch;
return r;
}
inline bool insert ( unsigned int val , int tip ){
int list = val & MOD; vector< pair<unsigned int,int> >::iterator itt;
if ( tip == 1 ){
for ( itt = H1[list].begin() ; itt != H1[list].end() ; ++itt ){
if ( itt->first == val ){
++itt->second;
return 0;
}
}
H1[list].pb(mp(val,1)); return 1;
}
else{
for ( itt = H2[list].begin() ; itt != H2[list].end() ; ++itt ){
if ( itt->first == val ){
++itt->second;
return 0;
}
}
H2[list].pb(mp(val,1)); return 1;
}
}
inline void erase ( unsigned int val , int tip ){
int list = val & MOD; vector< pair<unsigned int,int> >::iterator itt;
if ( tip == 1 ){
for ( itt = H1[list].begin() ; itt != H1[list].end() ; ++itt ){
if ( itt->first == val ){
--itt->second;
if ( !itt->second ){
*itt = H1[list][H1[list].size()-1]; H1[list].pop_back(); --nrst;
}
return ;
}
}
}
else{
for ( itt = H2[list].begin() ; itt != H2[list].end() ; ++itt ){
if ( itt->first == val ){
--itt->second;
if ( !itt->second ){
*itt = H2[list][H1[list].size()-1]; H2[list].pop_back(); --nrdr;
}
return ;
}
}
}
}
inline void citire () {
fread(buff,file_size,1,f);
n = next(); l = next(); u = next();
for ( i = 1 ; i <= n ; ++i ){
v[i] = next();
}
}
inline void solve () {
int st = 1,dr = 1;
for ( i = 1 ; i <= n ; ++i ){
nrst += insert(v[i],1);
while ( nrst > u ){
erase(v[st],1); ++st;
}
nrdr += insert(v[i],2);
while ( nrdr >= l ){
erase(v[dr],2); ++dr;
}
if ( nrst >= l && nrst <= u )
sol += dr - st;
}
fprintf(g,"%lld\n",sol);
}
int main () {
citire();
solve();
fclose(f);
fclose(g);
return 0;
}