Pagini recente » Cod sursa (job #1026441) | Cod sursa (job #982498) | Cod sursa (job #1600067) | Cod sursa (job #248190) | Cod sursa (job #1312691)
#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)
{
lenght++;
m[f[dr].first]++;
//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';
}