Cod sursa(job #2877991)
| Utilizator | Data | 25 martie 2022 17:47:23 | |
|---|---|---|---|
| Problema | Secventa 5 | Scor | 80 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <bits/stdc++.h>
using namespace std;
long long N, L, U;
unsigned int V[1<<20];
long long functie(int k){
unordered_map<unsigned int, int> x;
long long ct = 0;
for(int i=0, j=0; i < N; i++) {
x[V[i]]++;
while (x.size() > k) {
x[V[j]]--;
if (x[V[j]] == 0)
x.erase(V[j]);
j++;
}
ct += i - j + 1;
}
return ct;
}
int main(){
ifstream fin("secv5.in");
ofstream fout("secv5.out");
fin>>N>>L>>U;
for(int i=0; i<N; i++)
fin>>V[i];
fout<<functie(U) - functie(L-1);
}