Skip to content

Instantly share code, notes, and snippets.

@oha-yashi
Created June 15, 2020 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oha-yashi/0c9a4a87d9da33551d897ae12fe10a7d to your computer and use it in GitHub Desktop.
Save oha-yashi/0c9a4a87d9da33551d897ae12fe10a7d to your computer and use it in GitHub Desktop.
ABC170-E
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,Q;cin>>N>>Q;
vector<int> rate(N+1);
vector<int> belong(N+1);
vector<multiset<int>> youchien(200010);
multiset<int> maxenji;
for(int i=1; i<=N; i++){
int a,b;cin>>a>>b;
rate[i] = a;
belong[i] = b;
youchien[b].insert(a);
}
for(auto x: youchien){
if(x.empty())continue;
maxenji.insert(*x.rbegin());
}
for(int i=1; i<=Q; i++){
int c,d;cin>>c>>d;
int F = belong[c];
int T = d;
maxenji.erase(*youchien[F].rbegin());
if(!youchien[T].empty()){
maxenji.erase(*youchien[T].rbegin());
}
youchien[F].erase(rate[c]);
youchien[T].insert(rate[c]);
if(!youchien[F].empty()){
maxenji.insert(*youchien[F].rbegin());
}
maxenji.insert(*youchien[T].rbegin());
belong[c] = T;
cout<<*maxenji.begin()<<endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment