Pagini recente » Profil Lorien | Cod sursa (job #3283984) | Cod sursa (job #949568) | Profil alexdina | Cod sursa (job #2390340)
#include <iostream>
#include <unordered_map>
using namespace std;
#define N (1 << 20)
#define dim 8192
char ax[dim];
int pz;
int a[N + 1];
int n, L, R;
void cit(int &x) {
while (ax[pz] < '0' || ax[pz] > '9')
if (++pz == dim) fread(ax, 1, dim, stdin),pz = 0;
while (ax[pz] >= '0' && ax[pz] <= '9') {
x = x * 10 + ax[pz] - '0';
if (++pz == dim) fread(ax, 1, dim, stdin), pz = 0;
}
}
int newSize(const unordered_map<int, int> &h, int v) {
if (h.find(v) == h.end()) {
return h.size() + 1;
}
return h.size();
}
void solve() {
unordered_map<int, int> h1, h2;
int i, j1 = -1, j2 = 0, result = 0;
for (i = 0; i < n; ++i) {
for (++j1; j1 < n && h1.size() < L; ++j1) {
h1[a[j1]]++;
}
--j1;
for (; j2 < n && newSize(h2, a[j2]) <= R; ++j2) {
h2[a[j2]]++;
}
if (h1.size() == L) {
result += j2 - j1;
//cout << i << ": " << j2 -j1 <<endl;
}
//cout << i << " : " << j1 << " " << j2 << endl;
h1[a[i]]--;
if (h1[a[i]] == 0) {
h1.erase(a[i]);
}
h2[a[i]]--;
if (h2[a[i]] == 0) {
h2.erase(a[i]);
}
}
cout << result << endl;
}
int main() {
freopen("secv5.in", "r", stdin);
freopen("secv5.out", "w", stdout);
cit(n); cit(L); cit(R);
for (int i = 0; i < n; ++i) {
cit(a[i]);
//cout << a[i] << " ";
}
//cout << endl;
solve();
}