Pagini recente » Cod sursa (job #1440818) | Cod sursa (job #2719745) | Cod sursa (job #2794773) | Cod sursa (job #295028) | Cod sursa (job #1566156)
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <cmath>
using namespace std;
typedef unsigned long long int ull;
ifstream in("secv5.in");
ofstream out("secv5.out");
unordered_map<ull,ull> h;
const int MAX_SIZE = ( 1 << 20 )+1;
ull v[MAX_SIZE],n;
ull size(ull a , ull b)
{
return abs(a-b)+1;
}
ull distsec(ull nr)
{
ull sol = 0 ,
to_remove = 1;
for(int i= 1 ; i <= n ; i++)
{
h[v[i]]++;
while(h.size()> nr)
{
h[v[to_remove]]--;
if(h[v[to_remove]]==0)
h.erase(v[to_remove]);
to_remove++;
}
sol += size(i,to_remove); //updatam numarul de subsiruri
}
return sol;
}
int main()
{
ull l,u;
in >> n >> u >> l;
for(int i = 1 ; i <= n ; i++)
in >> v[i];
ull first = distsec(l);
h.clear();
ull second = distsec(u-1);
out<<first-second;
return 0;
}