Pagini recente » Borderou de evaluare (job #2296912) | Cod sursa (job #1197823) | Cod sursa (job #627493) | Cod sursa (job #471086) | Cod sursa (job #1312710)
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
using namespace std;
#define maxn 10000
int L, U, n;
pair<int, int> f[maxn];
map<int, int> m;
int main()
{
ifstream r("secv5.in");
ofstream w("secv5.out");
r>>n>>L>>U;
int i, ant=0, x, k=0;
for (i=0;i<n;i++)
{
r>>x;
if (x==ant) f[k].second++; //numarul de elemente de acelasi tip
else f[++k].second=1; //
f[k].first=x; // elementul respectiv
ant=x;
}
n=k;
//for (i=1;i<=n;i++) cout<<f[i].first<<' '<<f[i].second<<endl;
int lenght=0, solpart=1, sol=0, st=1, dr=1;
while (dr<n)
{
while (lenght<=U && dr<=n)
{
if (!m[f[dr].first]) lenght++;
m[f[dr].first]++;
//cout<<m[f[dr].first]<<endl;
//solpart*=f[dr].second;
if (lenght>=L) sol+=f[st].second*f[dr].second;
dr++;
}
if (dr>n) dr=n;
//cout<<lenght;
while (lenght>=L && st>=1)
{
m[f[st].first]--;
if (!m[f[st].first]) lenght--;
//solpart/=f[st].second;
st++;
if (lenght>=L) sol+=f[st].second*f[dr].second;
//st++;
}
}
w<<sol<<'\n';
}