Pagini recente » Cod sursa (job #3252646) | Cod sursa (job #2419284) | Cod sursa (job #322244) | Cod sursa (job #244561) | Cod sursa (job #2802732)
#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(true, i);
return make_pair(false, -1);
}
bool add(int n) {
auto found = find(n);
if (found.first)
h[n % MOD][found.second].second++;
else {
h[n % MOD].emplace_back(n, 1);
return true;
}
return false;
}
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 + (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;
}