Mai intai trebuie sa te autentifici.
Cod sursa(job #2755646)
| Utilizator | Data | 27 mai 2021 22:10:28 | |
|---|---|---|---|
| Problema | Secventa 5 | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 1.14 kb |
#include <fstream>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
long long sequences(int limit, vector<unsigned int> values){
long long result = 0;
unordered_map<unsigned int, int> hashtable;
unordered_map<unsigned int, int>::iterator it;
int left = 0;
for(int i = 0; i < values.size(); ++i){
it = hashtable.find(values[i]);
if(it != hashtable.end())
++it->second;
else hashtable.insert(pair<unsigned int, int>(values[i], 1));
while(hashtable.size() > limit){
it = hashtable.find(values[left]);
if(--it->second == 0) hashtable.erase(values[left]);
++left;
}
result += (i - left + 1);
}
return result;
}
int main()
{
ifstream cin("secv5.in");
ofstream cout("secv5.out");
int N, L, U;
cin >> N >> L >> U;
vector<unsigned int> values(N);
for(int i = 0; i < N; ++i)
cin >> values[i];
cout << sequences(U, values) - sequences(L - 1, values);
cin.close();
cout.close();
return 0;
}
