Cod sursa(job #2525214)

Utilizator AlexPascu007Pascu Ionut Alexandru AlexPascu007 Data 16 ianuarie 2020 21:38:18
Problema Secventa 5 Scor 0
Compilator cpp-32 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>
#define DIM (1<<20)+3
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
int n,l,i,u,a=1,b=1,sol,v[DIM];
unordered_map<int,int> st,dr;
int main() {
    fin>>n>>l>>u;
    for (i=1;i<=n;i++)
        fin>>v[i];
    for (i=1;i<=n;i++) {
        st[v[i]]++, dr[v[i]]++;
        while (st.size()>=l) {
            st[v[a]]--;
            if (st[v[a]]==0)
                st.erase(v[a]);
            a++;
        }
        while (dr.size()>u) {
            dr[v[b]]--;
            if (dr[v[b]]==0)
                dr.erase(v[b]);
            b++;
        }
        sol+=a-b;
    }
    fout<<sol;
    return 0;
}