Cod sursa(job #716113)

Utilizator BoSs_De_BosSSeFu SeFiLoR BoSs_De_BosS Data 18 martie 2012 12:32:40
Problema Secventa 5 Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<iostream>
#include<fstream>
#include<ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

ifstream in("secv5.in");
ofstream out("secv5.out");

unsigned int n,l,u,x[1000010],st,dr;
char s[20];
hash_map<unsigned int,unsigned int> h;

inline unsigned int sol(unsigned int dim) {
	h.clear();
	if(!dim)
		return 0;
	unsigned int sol=0,nr=0;
	
	for(st=1, dr=1; dr<=n; ++dr) {
		
		if(!h[x[dr]])
			++nr;
		h[x[dr]]++;
		
		while(nr>dim) {
			if(h[x[st]]==1)
				--nr;
			h[x[st]]--;
			++st;
		}
		
		sol += dr - st  + 1;
	}
	return sol;
}	

int main() {
	unsigned int i,xx;
	
	in >> n >> l >> u;
	
	for(i=1;i<=n;++i) {
		in.getline(s,30);
		xx = 0;
		for(int j = 0; s[j]!=0; ++j)
			xx = xx * 10 + s[j] - '0';
		x[i] = xx;
	}
	
	out << sol(u) - sol(l-1) << "\n";
	
	return 0;
}