Cod sursa(job #2877994)

Utilizator agabi21Totolici Alexandru agabi21 Data 25 martie 2022 17:48:56
Problema Secventa 5 Scor 80
Compilator cpp-64 Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 0.78 kb
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
ifstream f("secv5.in");
ofstream g("secv5.out");
int n,l,u;
unsigned int a[1050000];

long long secventa(int x)
{
    unordered_map<unsigned int,int> m;
    int low=0,high=0;
    long long nr=0,d=0;
    while(high<n)
    {
        if(m[a[high]]==0) d++;
        m[a[high]]++;
        while(d>x)
        {
            m[a[low]]--;
            if(m[a[low]]==0)
            {
                d--;
                m.erase(a[low]);
            }
            low++;
        }
        if(d<=x)
            nr+=high-low+1;
        high++;

    }
    return nr;

}
int main()
{
    f>>n>>l>>u;
    for(int i=0; i<n; i++)
        f >> a[i];
    g<<secventa(u)-secventa(l-1);
    return 0;

}