Pagini recente » Cod sursa (job #2839125) | Cod sursa (job #626465) | Cod sursa (job #586916) | Cod sursa (job #3166100) | Cod sursa (job #1144873)
#include <vector>
#include <fstream>
using namespace std;
ifstream in("secv5.in");
ofstream out("secv5.out");
const int NMAX = (1<<20);
const int MOD = 666013;
struct SIR{
int v,c;
};
vector <SIR> H1[MOD], H2[MOD], H3[MOD];
int v[NMAX+1], N,L,U;
int l= 1, r= 0;
int cn_l= 1, cn_r= 0, poz= 0;
int pune_1( int x ) {
int k= x % MOD, gasit= 0;
for( int i= 0; i<(int)H1[k].size(); i++ ) {
if( x == H1[k][i].v ) {
gasit= 1;
++H1[k][i].c;
}
}
if( gasit == 0 ) {
SIR aux;
aux.v= x; aux.c= 1;
H1[k].push_back( aux );
}
return 1-gasit;
}
void pune_2( int x ) {
int k= x % MOD, gasit= 0;
for( int i= 0; i<(int)H2[k].size(); i++ ) {
if( x == H2[k][i].v ) {
gasit= 1;
++H1[k][i].c;
}
}
if( gasit == 0 ) {
SIR aux;
aux.v= x; aux.c= 1;
H2[k].push_back( aux );
}
}
void pune_3( int x ) {
int k= x % MOD, gasit= 0;
for( int i= 0; i<(int)H3[k].size(); i++ ) {
if( x == H3[k][i].v ) {
gasit= 1;
++H3[k][i].c;
}
}
if( gasit == 0 ) {
SIR aux;
aux.v= x; aux.c= 1;
H3[k].push_back( aux );
}
}
int unic_2( int x ) {
int k= x % MOD, gasit= 0;
for( int i= 0; i<(int)H2[k].size(); i++ ) {
if( x == H2[k][i].v ) {
gasit= 1;
}
}
return 1-gasit;
}
int unic_3( int x ) {
int k= x % MOD, gasit= 0;
for( int i= 0; i<(int)H3[k].size(); i++ ) {
if( x == H3[k][i].v ) {
gasit= 1;
}
}
return 1-gasit;
}
int main()
{
in >> N >> L >> U;
int dist= 0, R= 0;
while( dist < L && poz < N ) {
++poz;
in >> v[poz];
dist+= pune_1( v[poz] );
}
l= 1; r= 1;
while( dist-cn_r >= L ) {
cn_r+= unic_2( r+1 );
++r;
}
R+= r-l+1;
while( poz < N ) {
++poz;
in >> v[poz];
dist+= pune_1( v[poz] );
while( dist-cn_r >= L ) {
cn_r+= unic_2( v[r+1] );
r++;
}
while( dist-cn_l >= U ) {
cn_l+= unic_3( v[l] );
l++;
}
R+= r-l+1;
}
out << R << '\n';
return 0;
}