显示原始代码
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n, a_i;
cin >> n;
multiset<long long> hats;
for (int i = 0; i < n; i++) {
cin >> a_i;
hats.insert(a_i);
}
int q, operate;
cin >> q;
int j = 0 while (j < q) {
int l, r;
cin >> operate;
j++;
switch (operate) {
case 1: {
int x;
cin >> x;
hats.insert(x);
break;
}
case 2: {
int y;
cin >> y;
auto it = hats.find(y);
if (it != hats.end())
hats.erase(it);
break;
}
case 3: {
long long sum = 0;
cin >> l >> r;
for (auto i = hats.lower_bound(l); i != hats.upper_bound(r); i++) {
sum += *i;
}
cout << sum << '\n';
break;
}
default:
break;
}
}
return 0;
}