Pagini recente » Prezentare infoarena | Cod sursa (job #2109545) | Cod sursa (job #244350) | Cod sursa (job #1301791) | Cod sursa (job #1566187)
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
ofstream out("secv5.out");
const int MAX_SIZE = ( 1 << 20 )+1;
unsigned long long v[MAX_SIZE],n;
int main()
{
FILE *f = fopen("secv5.in","r");
unsigned long long l,u;
unordered_map<unsigned ,unsigned> h1,h2;
unsigned long long sol1 = 0 ,sol2 = 0,
to_remove1 = 1,to_remove2 = 1;
fscanf(f,"%llu%llu%llu",&n,&u,&l);
for(int i = 1 ; i <= n ; i++)
{
fscanf(f,"%llu",&v[i]);
h1[v[i]]++;
while(h1.size()> l)
{
h1[v[to_remove1]]--;
if(h1[v[to_remove1]]==0)
h1.erase(v[to_remove1]);
to_remove1++;
}
sol1 += i-to_remove1 +1; //updatam numarul de subsiruri
h2[v[i]]++;
while(h2.size()> u-1)
{
h2[v[to_remove2]]--;
if(h2[v[to_remove2]]==0)
h2.erase(v[to_remove2]);
to_remove2++;
}
sol2 += i-to_remove2 +1;
}
out<<sol1-sol2;
return 0;
}