Pagini recente » Cod sursa (job #33032) | Cod sursa (job #1607226) | Cod sursa (job #1753970) | Cod sursa (job #1857408) | Cod sursa (job #2802747)
#include <bits/stdc++.h>
using namespace std;
ifstream in("secv5.in");
ofstream out("secv5.out");
using ll = long long;
const int maxN = (1 << 20) + 1;
const int MOD = 700027;
int n, mi, ma;
int v[maxN];
struct Hash {
vector<vector<pair<int, int>>> h;
Hash() : h(MOD, vector<pair<int, int>>()) {}
pair<bool, int> find(int n) {
int x = n % MOD;
for (int i = 0; i < (int)h[x].size(); i++)
if (h[x][i].first == n)
return make_pair((bool)(h[x][i].second != 0), i);
h[x].emplace_back(n, 0);
return make_pair(false, (int)h[x].size() - 1);
}
bool add(int n) {
auto found = find(n);
h[n % MOD][found.second].second++;
if (found.first)
return false;
return true;
}
bool del(int n) {
auto found = find(n);
h[n % MOD][found.second].second--;
if (h[n % MOD][found.second].second == 0)
return true;
return false;
}
};
ll solve(int val) {
Hash H;
ll ans = (ll)0;
int l = 0, cnt = 0;
for (int i = 0; i < n; i++) {
cnt += H.add(v[i]);
while (cnt > val)
cnt -= H.del(v[l++]);
ans = (ll)ans + (ll)1 * (i - l + 1);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
in.tie(NULL);
in >> n >> mi >> ma;
for (int i = 0; i < n; i++)
in >> v[i];
out << solve(ma) - solve(mi - 1) << "\n";
return 0;
}