Cod sursa(job #1312691)

Utilizator diana-t95FMI Tudoreanu Diana Elena diana-t95 Data 9 ianuarie 2015 20:51:09
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#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';
}