Pagini recente » Cod sursa (job #1151311) | Cod sursa (job #1651717) | Cod sursa (job #595185) | Cod sursa (job #2061995) | Cod sursa (job #1312650)
#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+=solpart;
dr++;
}
while (lenght>=L && st>=1)
{
m[f[st].first]--;
if (!m[f[st].first]) lenght--;
solpart/=f[st].second;
if (lenght>=L) sol+=solpart;
st++;
}
}
w<<sol<<'\n';
}