Pagini recente » Cod sursa (job #241279) | Cod sursa (job #396369) | Cod sursa (job #1450325) | Cod sursa (job #2599834) | Cod sursa (job #2321735)
#include <bits/stdc++.h>
using namespace std;
//ifstream fin("secv5.in");
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 >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';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 >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long 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;
}
} fin("matroid.in");
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
} fin("secv5.in");
long long n, l, u;
long long x[(1<<20)+1];
unordered_map<long long, int>ap;
long long solve(long long l)
{
ap.clear();
long long j=1, sol=0;
for(int i=1; i<=n; ++i)
{
++ap[x[i]];
while(ap.size()>l)
{
--ap[x[j]];
if(ap[x[j]]==0) ap.erase(x[j]);
++j;
}
sol=sol+i-j+1;
}
return sol;
}
int main()
{
fin>>n>>l>>u;
for(int i=1; i<=n; ++i) fin>>x[i];
fout<<solve(u)-solve(l-1)<<"\n";
return 0;
}