Cod sursa(job #1825830)

Utilizator liviu23Liviu Andrei liviu23 Data 9 decembrie 2016 18:48:38
Problema Secventa 5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <unordered_map>
#define DIM (1<<20)+5
#define M 681253
#define uint unsigned
using namespace std;

int n,l,u;
uint v[DIM];

long long countSeq(int len) {
    int j=1;
    long long ans=0;
    unordered_map<uint,int> h;
    for(int i=1;i<=n;i++) {
        h[v[i]]++;
        while(h.size()>len) {
            h[v[j]]--;
            if(h[v[j]]==0)
                h.erase(v[j]);
            j++;
        }
        ans+=1LL*(i-j+1);
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    ifstream fin("secv5.in");
    ofstream fout("secv5.out");
    fin>>n>>l>>u;
    for(int i=1;i<=n;i++)
        fin>>v[i];
    fout<<countSeq(u)-countSeq(l-1);
    return 0;
}