Cod sursa(job #2608825)

Utilizator DarkwarriorRobert Gaspar Darkwarrior Data 1 mai 2020 19:39:50
Problema Secventa 5 Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;

ifstream f("secv5.in");
ofstream g("secv5.out");
int n,l,u;
unsigned int v[2000041];
long long secv(long long k){
    unordered_map <long long, int> m;
    long long ed=0,secve=0,j=1;
    for(int i=1;i<=n;i++){
        if(m[v[i]]==0){
            ed++;
        }
        m[v[i]]++;
        while(ed>k){
            j++;
            m[v[j-1]]--;
            if(m[v[j-1]]==0){ed--;
            m.erase(m[v[j-1]]);
            }
        }
        if(ed<=k){
            secve+=i-j+1;
        }
    }
    return secve;
}
int main()
{
    int nr;
    long long lsecv,usecv;
    f>>n>>l>>u;
    for(int i=1;i<=n;i++){
        f>>v[i];
    }
    lsecv=secv(l-1);
    usecv=secv(u);
    g<<usecv-lsecv;
    return 0;
}