Cod sursa(job #1315677)

Utilizator radudorosRadu Doros radudoros Data 12 ianuarie 2015 23:36:17
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 0.61 kb
#include <fstream>
#include <unordered_map>
using namespace std;

const int NMAX = (1 << 20) + 1;

ifstream fin("secv6.in");
ofstream fout("secv6.out");

unsigned int v[NMAX];
unordered_map<unsigned int, unsigned int> h;
int n;
long long secv(int x)
{
	h.clear();
	long long s = 0;
	int j = 1;
	for (int i = 1; i <= n; i++)
	{
		h[v[i]]++;
		while (x < h.size())
		{
			h[v[j]]--;
			if (h[v[j]] == 0)
				h.erase(v[j]);
			j++;
		}
		s += (i - j + 1);
	}
}

int main()
{
	int  l, u;
	fin >> n >> l >> u;
	for (int i = 1; i <= n; i++)
		fin >> v[i];
	
	fout << secv(u) - secv(l - 1);


}