Cod sursa(job #2601899)

Utilizator 1chiriacOctavian Neculau 1chiriac Data 15 aprilie 2020 13:46:23
Problema Secventa 5 Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin ("secv5.in");
ofstream fout ("secv5.out");
const unsigned int modu=666013;
vector < pair <unsigned int ,int > > hashis[modu];
unsigned int l,u,v[(1<<20)+3],p0,p1,var,kontor0,kontor1;unsigned long long ans;int n;
bool insert_hash (unsigned int x) {
	var=x%modu;
	for(int i=0;i<(int)hashis[var].size();++i)
		if(hashis[var][i].first==x) {
			++hashis[var][i].second;
			if(hashis[var][i].second==1)
				return true;
			else
				return false;
		}
	hashis[var].push_back({x,1});
	return true;
}
bool delete_hash (unsigned int x) {
	var=x%modu;
	for(int i=0;i<(int)hashis[var].size();++i)
		if(hashis[var][i].first==x) {
			if(hashis[var][i].second>0) {
				--hashis[var][i].second;
				if(hashis[var][i].second==0)
					return true;
			}
			else
				return false;
		}
	return false;
}
int main () {
	fin>>n>>l>>u;p0=1;p1=1;--l;
	for(int i=1;i<=n;++i) {
		fin>>v[i];
		if(insert_hash(v[i])==true) {
			++kontor0;
			while(kontor0>l) {
				if(delete_hash(v[p0])==true)
					--kontor0;
				++p0;
			}
			//if(kontor0<l)
				//--p0,ok=insert_hash(v[p0],0),++kontor0;
		}	
		if(kontor0==l)
			ans=ans+p0;
	}
	for(int i=1;i<=n;++i) {
		if(insert_hash(v[i])==true) {
			++kontor1;
			while(kontor1>u) {
				if(delete_hash(v[p1])==true)
					--kontor1;
				++p1;
			}
		}
		if(kontor1>=l)
			ans-=p1;
	}
	fout<<ans;
	return 0;
}