Pagini recente » Cod sursa (job #422879) | Cod sursa (job #1634945) | Cod sursa (job #1871680) | Cod sursa (job #1514961) | Cod sursa (job #1566201)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#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;
unsigned long long distsec(unsigned nr)
{
unordered_map<unsigned ,int> h;
unsigned long long 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 += i-to_remove +1; //updatam numarul de subsiruri
}
return sol;
}
int main()
{
FILE *f = fopen("secv5.in","r");
unsigned long long l,u;
fscanf(f,"%llu%llu%llu",&n,&u,&l);
for(int i = 1 ; i <= n ; i++)
fscanf(f,"%llu",&v[i]);
out<< distsec(l) - distsec(u-1);
return 0;
}