显示原始代码
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
#define N 20000
using namespace std;
int main() {
int q;
cin >> q;
int S[N] = { 0 };
int x, c;
int X[q] = { 0 };
int k = 0;
for (int i = 0; i < q; i++) {
int o;
cin >> o;
if (o == 1) {
cin >> x;
S[x]++;
X[k] = x;
k++;
}
else if (o == 2) {
cin >> x >> c;
if (c >= S[x]) {
S[x] = 0;
} else {
S[x] = S[x] - c;
}
}
else if (o == 3) {
int temp;
for (int j = 0; j < k; j++) {
if (X[0] < X[j]) {
temp = X[0];
X[0] = X[j];
X[j] = temp;
}
}
int min, max;
for (int j = 0; j < N; j++) {
if (S[j] != 0) {
min = j;
break;
}
}
for (int j = X[0]; j >= 0; j--) {
if (S[j] != 0) {
max = j;
break;
}
}
cout << max - min << endl;
}
}
return 0;
}