Cod sursa(job #3189186)

Utilizator Roberthinio7Robert Dragan Roberthinio7 Data 4 ianuarie 2024 16:51:32
Problema Secventa 5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
#include<iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
long long int v[2000001];
int n,l,u;
long long numsec(int lungm){
    long long int i=0,j=0,nrsecv=0,cnt=0;
    unordered_map <long long int, int> f;
    while(i<n){
        if(f[v[i]]==0) cnt++;
        f[v[i]]++;i++;
        while(cnt>lungm){
            f[v[j]]--;
            if(f[v[j]]==0)
                cnt--;
            j++;
        }
        nrsecv=nrsecv+i-j;
    }
    return nrsecv;
}
int main()
{
    ifstream cin("secv5.in");
    ofstream cout("secv5.out");
    cin >> n >> l >> u;
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    cout << numsec(u)-numsec(l-1);
    return 0;
}