-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoctorkattis.cpp
69 lines (65 loc) · 1.9 KB
/
doctorkattis.cpp
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
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
priority_queue<tuple<int,int,string>> pq;
unordered_map<string, ii> db;
unordered_map<string, int> update;
unordered_map<string, int> del;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("doctor.in","r",stdin);
int n; cin >> n;
while (n--) {
int a; cin >> a;
if (a == 0) { //add
string name; int p; cin >> name >> p;
db[name] = ii(p,n);
tuple<int,int,string> id = make_tuple(p,n,name);
pq.emplace(id);
} else if (a == 1) { //update
string name; int p; cin >> name >> p;
db[name].first += p;
tuple<int,int,string> id = make_tuple(db[name].first,db[name].second,name);
pq.emplace(id);
update[name] = 1;
} else if (a == 2) { //del
string name; cin >> name;
del[name] = 1;
} else { //query
string output = "The clinic is empty";
while (!pq.empty()) {
tuple<int,int,string> curr = pq.top();
string name = get<2>(curr);
if (del[name]) {
pq.pop(); continue;
}
if (update[name]) {
if (update[name] == 1) {
output = name; break;
update[name] += 1;
}
else {
pq.pop(); update[name] = 0;
continue;
}
}
output = name;
break;
}
cout << output << '\n';
}
}
}