Cod sursa(job #3175173)

Utilizator mhyasdArdelean Mihai mhyasd Data 25 noiembrie 2023 13:30:55
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 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;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
unordered_map <int, int> f;
unordered_map <int, int> f1;
int v[2000000];

int main()
{
    int n,x,y,cnt=0,l=1,l1=1,ras=0,ras1=0;
    fin>>n>>x>>y;
    x--;
    for(int i=1;i<=n;i++) {
        fin>>v[i];
        f[v[i]]++;
        if(f[v[i]]==1) {
            cnt++;
            while(cnt>x) {
                f[v[l]]--;
                if(f[v[l]]==0) cnt--;
                l++;
            }
        }
        ras+=i-l+1;
    }
    cnt=0;
    for(int i=1;i<=n;i++) {
        f1[v[i]]++;
        if(f1[v[i]]==1) {
            cnt++;
            while(cnt>y) {
                f1[v[l1]]--;
                if(f1[v[l1]]==0) cnt--;
                l1++;
            }
        }
        ras1+=i-l1+1;
    }
    fout<<ras1-ras;

    return 0;
}