Pagini recente » Cod sursa (job #404066) | Cod sursa (job #984095) | Cod sursa (job #966382) | Cod sursa (job #1892857) | Cod sursa (job #2877987)
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
ifstream f("secv5.in");
ofstream g("secv5.out");
int n,l,u;
int a[1050000];
int secventa(int x)
{
unordered_map<int,int> m;
int low=0,high=0;
int nr=0,d=0;
while(high<n)
{
if(m[a[high]]==0) d++;
m[a[high]]++;
while(d>x)
{
m[a[low]]--;
if(m[a[low]]==0)
{
d--;
m.erase(a[low]);
}
low++;
}
if(d<=x)
nr+=high-low+1;
high++;
}
return nr;
}
int main()
{
f>>n>>l>>u;
for(int i=0; i<n; i++)
f >> a[i];
g<<secventa(u)-secventa(l-1);
return 0;
}