Pagini recente » Cod sursa (job #2748190) | Cod sursa (job #1312687) | Cod sursa (job #2890457)
//#include <bits/stdc++.h>
//using namespace std;
//
//ifstream in("pariuri.in");
//ofstream out("pariuri.out");
//
//int main(){
//
//// Problema 1:
// unordered_map<int, int> D;
// int N, M, timp, bani;
// in >> N;
// // citirea
// for (int i = 0; i < N; ++i) {
// in >> M;
// for (int j = 0; j < M; ++j) {
// in >> timp >> bani;
// D[timp] += bani;
// }
// }
// //afis
// out << D.size() << '\n';
// for (auto pair : D) {
// out << pair.first << ' ' << pair.second << ' ';
// }
// return 0;
//}
//#include <bits/stdc++.h>
//using namespace std;
//
//ifstream in("secv5.in");
//ofstream out("secv5.out");
//
//
//int main(){
// int L, U, N;
// cin >> N >> L >> U;
// int same = 0,distinct = 0, sol = 0;
// vector<unsigned int> inc;
// unordered_map<unsigned int, int> map;
// distinct = 0;
// unsigned int curent;
// while (distinct != L){
// cin >> curent;
// inc.push_back(curent);
// if(map[curent] == 0) distinct++;
// map[curent] += 1;
// }
// sol = 1;
// int x = 0;
// int k = inc.size();
// for (int i = 0; i < N-k; ++i) {
// if(distinct >= U){
// if(map[inc[0]] == 1) distinct--;
// map[inc[0]] -= 1;
// inc.erase(inc.begin());
// sol += x;
// x = 0;
// }
// cin >> curent;
// map[curent] += 1;
// inc.push_back(curent);
// sol++;
// x++;
// if(map[curent] == 1)distinct++;
// }
// cout << sol;
// return 0;
//}
#include <bits/stdc++.h>
using namespace std;
ifstream in("secv5.in");
ofstream out("secv5.out");
int nrSecv(int D, vector<unsigned int> v){
unordered_map<unsigned int, int> map;
int j = 0, nr = 0;
for (int i=0;i<v.size();i++)
{
map[v[i]]++;
while(map.size()>D){
map[v[j]]--;
if(map[v[j]]==0){
map.erase(map.find(v[j]));
}
j++;
}
nr+=(i-j+1);
}
return nr;
}
int main() {
int L, U, N;
in >> N >> L >> U;
int curent;
int same = 0, distinct = 0, sol = 0;
vector<unsigned int> inc;
for (int i = 0; i < N; ++i) {
in >> curent;
inc.push_back(curent);
}
out << nrSecv(U,inc) - nrSecv(L-1,inc);
return 0;
}