Pagini recente » Cod sursa (job #3176864) | Cod sursa (job #2968389) | Cod sursa (job #1432508) | Cod sursa (job #263447) | Cod sursa (job #2694705)
#include <iostream>
#include <fstream>
#include <unordered_map>
const int NMAX = (1 << 20);
int n, qLeft, qRight;
unsigned int a[1 + NMAX];
std::unordered_map<unsigned int, int> hashmap;
void read() {
std::ifstream in("secv5.in");
in >> n >> qLeft >> qRight;
for (int i = 1; i <= n; ++i)
in >> a[i];
}
int64_t countSeq(int target) {
int left = 1, cnt = 0;
int64_t ans = 0;
for (int i = 1; i <= n; ++i) {
++hashmap[a[i]];
if (hashmap[a[i]] == 1)
++cnt;
while (cnt > target) {
--hashmap[a[left]];
if (hashmap[a[left]] == 0)
--cnt;
++left;
}
ans += (int64_t)(i - left + 1);
}
return ans;
}
int main() {
read();
int64_t left = countSeq(qLeft - 1);
for (int i = 1; i <= n; ++i)
hashmap[a[i]] = 0;
int64_t right = countSeq(qRight);
std::ofstream out("secv5.out");
out << right - left << '\n';
return 0;
}