Pagini recente » Cod sursa (job #1359629) | Cod sursa (job #307973) | Cod sursa (job #2019057) | Cod sursa (job #1567786) | Cod sursa (job #2454783)
#include <bits/stdc++.h>
using namespace std;
ofstream fout("secv5.out");
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (unsigned int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
const int DIM = (1 << 20) + 7;
unordered_map <unsigned int, int> H1;
unordered_map <unsigned int, int> H2;
unsigned int v[DIM];
unsigned int n;
unsigned int l, r;
main()
{
InParser fin("secv5.in");
fin >> n >> l >> r;
for(int i = 1; i <= n; i++)
fin >> v[i];
long long l1 = 1, l2 = 1;
long long ans = 0;
for(int i = 1; i <= n; i++)
{
H1[v[i]]++;
H2[v[i]]++;
while(H1.size() > r)
{
H1[v[l1]]--;
if(H1[v[l1]] == 0)
H1.erase(v[l1]);
l1++;
}
while(H2.size() >= l)
{
H2[v[l2]]--;
if(H2[v[l2]] == 0)
H2.erase(v[l2]);
l2++;
}
ans += i - l1 + 1;
ans -= i - l2 + 1;
}
fout << ans;
}