Cod sursa(job #1780993)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 16 octombrie 2016 17:17:19
Problema Secventa 5 Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>

#define NMax (1<<20 + 2)
#define mod 666013
using namespace std;
ifstream f("secv5.in");
ofstream g("secv5.out");

unsigned int n,l,u,first,ans;
unsigned int a[NMax];

int Count(int l){
    map<unsigned int,unsigned int> H;

    first = 1;
    ans = 0;
    for(int i = 1; i <= n; ++i){
        H[a[i]]++;
        while(H.size() > l){
            H[a[first]]--;
            if(H[a[first]] == 0){
                H.erase(a[first]);
            }
            first++;
        }
        ans += (i - first + 1);
    }
    return ans;
}
int main()
{
    f >> n >> l >> u;
    for(int i = 1; i <= n; ++i)
        f >> a[i];
    g << Count(u) - Count(l - 1) << '\n';
    return 0;
}