include iostream include string include vector include iomanip include

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <set>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define null NULL
typedef long long ll;
const int N = 100010;
struct Node;
typedef Node* pNode;
struct Node {
long long key, prior;
long long w = 1;
pNode l = NULL, r = NULL;
Node(){}
Node(long long _key): key(_key) {
prior = rand();
}
Node(ll _key, ll _prior): key(_key), prior(_prior) {}
};
Node init[N];
ll cnt = 0;
inline pNode newNode(ll key) {
init[cnt].key = key;
init[cnt].prior = rand();
return &init[cnt++];
}
pNode root = NULL;
long long W(pNode p) {
return !p ? 0 : p->w;
}
void split(pNode T, pNode& L, pNode& R, ll x) {
if(!T) {
L = NULL, R = NULL;
return;
}
if(T->key < x) {
split(T->r, T->r, R, x);
L = T;
} else {
split(T->l, L, T->l, x);
R = T;
}
if(L) L->w = 1 + W(L->l) + W(L->r);
if(R) R->w = 1 + W(R->l) + W(R->r);
}
void merge(pNode &T, pNode L, pNode R) {
if(!L || !R) {
T = L ? L : R;
if(T) T->w = L ? L->w : R->w;
return;
}
if(L->prior > R->prior) {
merge(L->r, L->r, R);
T = L;
} else {
merge(R->l, L, R->l);
T = R;
}
if(T) {
T->w = 1;
if(L) T->w += L->w;
if(R) T->w += R->w;
}
}
void insert(pNode& T, pNode x) {
if(!T) {
T = x;
return;
}
if(T->prior > x->prior) {
insert(x->key < T->key ? T->l : T->r, x);
} else {
split(T, x->l, x->r, x->key);
T = x;
}
T->w = 1;
if(T->l) T->w += W(T->l);
if(T->r) T->w += W(T->r);
}
inline long long count(pNode p, ll x) {
if(!p) return 0;
if(p->key < x) return count(p->r, x);
else return W(p->r) + 1 + count(p->l, x);
}
inline void erase(pNode& p, ll x) {
if(p->key == x) {
merge(p, p->l, p->r);
} else {
erase(x < p->key ? p->l : p->r, x);
}
}
int main() {
ios_base::sync_with_stdio(false);
// cout <<fixed <<setprecision(15);
srand(134254);
// freopen("in.txt", "r", stdin);
// cout <<getOldNom(2) <<endl;
// return 0;
long long ans = 0;
for(;;) {
string type;
cin >>type;
if(type == "BID") {
double dprice;
cin >>dprice;
ll price((dprice+1e-9) * 100);
insert(root, newNode(price));
} else if(type == "DEL") {
double dprice;
cin >>dprice;
ll price((dprice+1e-9) * 100);
erase(root, price);
} else if(type == "SALE") {
long long k;
double dprice;
cin >>dprice;
ll price((dprice+1e-9) * 100);
cin >>k;
ll cansale = count(root, price);
// cout <<"can sale: " <<cansale <<endl;
ans += min(cansale, k);
} else {
break;
}
}
cout <<fixed <<setprecision(2) <<ans * 0.01 <<endl;
return 0;
}