Cod sursa(job #2269532)

Utilizator ptudortudor P ptudor Data 26 octombrie 2018 09:49:40
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;
const int nmax=1048600;
int N,L,U,a[nmax];
queue <int> q;
unordered_map <int,int> M;
int secv(int x)
{int i,k=0,fin=0;
    for (i=1;i<=N;i++)
    {
        q.push(a[i]);
        M[a[i]]++;
        if (M[a[i]]==1)k++;
        while (k>x)
        {
            if (M[q.front()]==1)k--;
            M[q.front()]--;
            q.pop();
        }
        fin+=q.size();
    }
    while (!q.empty())
    {
        M[q.front()]--;
        q.pop();
    }
    return fin;
}
int main()
{int i;
    ifstream in("secv5.in");
    ofstream out("secv5.out");
    in>>N>>L>>U;
    for (i=1;i<=N;i++)
    {
        in>>a[i];
    }
    out<<secv(U)-secv(L-1)<<"\n";
}