Cod sursa(job #2454769)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 9 septembrie 2019 20:27:17
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>

using namespace std;

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

const long long DIM = (1 << 20) + 7;

unordered_map <unsigned int, int> H;

unsigned int v[DIM];

unsigned int n;

long long get(int p)
{
	H.clear();
	
	long long l = 1;
	long long ans = 0;
	
	for(int i = 1; i <= n; i++)
	{
		H[v[i]]++;
		
		while(H.size() > p)
		{
			H[v[l]]--;
			
			if(H[v[l]] == 0)
				H.erase(v[l]);
			
			l++;
		}
		
		ans += i - l + 1;
	}
	
	return ans;
}

unsigned int l, r;

main()
{
	fin >> n >> l >> r;
	
	for(int i = 1; i <= n; i++)
		fin >> v[i];
	
	fout << get(r) - get(l);
}