-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabc170e.cpp
More file actions
65 lines (51 loc) · 1.3 KB
/
abc170e.cpp
File metadata and controls
65 lines (51 loc) · 1.3 KB
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
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,q;
cin >> n >> q;
vector<int> baby_rate(n + 1);
vector<int> baby_from(n + 1);
vector<multiset<int>> st(200020);
multiset<int> max_rate;
for (int i = 0; i < 200020; i++) {
st[i].insert(-1);
}
for (int i = 1; i <= n; i++) {
int a,b;
cin >> a >> b;
st[b].insert(a);
baby_rate[i] = a;
baby_from[i] = b;
}
for (int i = 0; i < 200020; i++) {
if(*st[i].rbegin() != -1) {
max_rate.insert(*st[i].rbegin());
}
}
while(q--) {
int c,to;
cin >> c >> to;
int from = baby_from[c];
int rate = baby_rate[c];
baby_from[c] = to;
bool changed = false;
if(rate == *st[from].rbegin()) {
max_rate.erase(max_rate.find(rate));
changed = true;
}
int pre_to_max = *st[to].rbegin();
if(pre_to_max != -1) max_rate.erase(max_rate.find(pre_to_max));
st[from].erase(st[from].find(rate));
st[to].insert(rate);
int from_max = *st[from].rbegin();
int to_max = *st[to].rbegin();
if(from_max != -1 && changed) max_rate.insert(from_max);
max_rate.insert(to_max);
cout << *max_rate.begin() << '\n';
}
return 0;
}