Pagini recente » Cod sursa (job #2353851) | Cod sursa (job #2957508) | Cod sursa (job #2958584) | Cod sursa (job #109332) | Cod sursa (job #2694701)
#include <iostream>
#include <fstream>
#include <unordered_map>
const int NMAX = (1 << 20);
int n, qLeft, qRight;
int a[1 + NMAX];
std::unordered_map<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;
return 0;
}